🔗
Networking concepts
  • Introduction
  • DNS
    • Introduction
    • DNS query
  • SSH
    • Introduction
    • Basics
    • SSH tunneling
      • Direct SSH tunnel
      • Reverse SSH tunnel
      • Dynamic SSH tunnel
    • SSH public key authentication
    • Port forwarding with virtual interface
    • sshd
    • scp/sftp
  • 🔫Networking tools
    • configuration & information
      • ip
      • netstat/netsh
      • ifconfig/ipconfig/iwconfig
      • arp
      • route
      • ps
      • ss
      • lsof
      • pgrep
      • nmcli
      • Information about services/processes & PID
    • monitoring & troubleshooting
      • ping
      • tracert/traceroute
      • mtr
      • iperf3
    • domain information
      • dig/nslookup
      • whois
      • host
    • capture & analysis
      • tcpdump
      • ngrep
      • wireshark
    • firewall & security
      • iptables
      • nft
    • services
      • dnsmasq
      • hostapd
      • RDP/VNC
      • ngrok
      • networking.service
      • NetworkManager.service
      • nginx
      • apache
      • nfs
    • miscellaneous
      • cURL
      • wget
      • netwox
      • netcat
      • openssl
      • socat
      • ftp
      • smbclient
    • proxy & tunneling
      • proxychains
    • Programming/scripting
      • Python
      • C
  • 🤩Interesting concepts
    • Simple tips & tricks
    • Network hole punching
    • SSH Over HTTPS
  • Network ports & services cheat sheet
    • 20/21/tcp ~ ftp
    • 22/tcp ~ ssh
    • 23/tcp ~ telnet
    • ...
  • For-fun projects
    • Raspberry pi + Windows machine experiments
Powered by GitBook
On this page
  • Setup a Dynamic Host Configuration Protocol (DHCP) server
  • Connecting to the DHCP server
  • Linux
  • Windows
  1. Networking tools
  2. services

dnsmasq

dnsmasq is free software providing services such as Domain Name System (DNS) caching, Dynamic Host Configuration Protocol (DHCP) server, and many more.

Setup a Dynamic Host Configuration Protocol (DHCP) server

The following are the steps to setup a DHCP server with dnsmasq:

  1. Setup a static IP address on the machine acting as the DHCP server

    • The steps to configure a static IP address are outlined in the networking.service sub-section under this section (https://jarrettgxz-sec.gitbook.io/networking-concepts/networking-tools/services/networking.service)

  2. Configure the DHCP server settings from the /etc/dnsmasq.conf file

a) Open up /etc/dnsmasq.conf on a text editor

$ sudo vim /etc/dnsmasq.conf
# OR
$ sudo nano /etc/dnsmasq.conf

b) Add the following lines at the bottom

  • Replace iface, dhcp_start_range, dhcp_end_range and lease_time with the appropriate values

  • The iface value used should match the one that have been configured from part 1 (static IP address allocation)

...
interface=<iface>
dhcp-range=<dhcp_start_range>,<dhcp_end_range>,<lease_time>

c) Save the file

  1. Restart the dnsmasq daemon

$ sudo systemctl restart dnsmasq.service

Example

Setup a machine as a DHCP server on the interface eth0, with the static IP address of 88.88.88.88, and a DHCP pool range of 88.88.88.0 to 88.88.88.87. The lease time will be set to 24 hours.

# 1. Set static IP address (Debian-based distro)
# Notice that only a few important fields are included
$ sudo vim /etc/network/interfaces
...
auto eth0
iface eth0 inet static
  address 88.88.88.88
  netmask 255.255.255.0
  

# 2. Edit the dnsmasq configuration file
$ sudo vim /etc/dnsmasq.conf 
...
interface=eth0
dhcp-range=88.88.88.0,88.88.88.87,24h

# 3. Restart the dnsmasq daemon and check the status
$ sudo systemctl restart dnsmasq.service
$ sudo systemctl status dnsmasq.service

Connecting to the DHCP server

Simply connect a physical ethernet adapter from the client interface to the interface on the DHCP server machine that was configured.

Subsequently, verify if the client interface have been successfully configured with an IP address from the DHCP range. Perform the following on the client machine — a few troubleshooting steps will be outlined too.

Linux

# Verify the configuration (run either one of the commands) 
$ ifconfig
$ ip a

Look for the paragraph where the client interface is configured (eg. eth0)

.:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> ... state UP  ...
    link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff
    inet 88.88.88.xxx/24 brd 88.88.88.255 scope global eth0

The IP address displayed after inet should be within the DHCP pool range defined in the DHCP server configurations, and the state should be UP.

Troubleshooting on Linux

The following actions can be taken to resolve any issues:

  1. Reset the lease and request for a new IP address via a DHCP query:

# Send a DHCP request
$ dhclient -r [iface]
$ dhclient [iface]

# eg. on interface eth0
$ dhclient -r eth0
$ dhclient eth0
  1. Reset the client network interface

$ sudo ip link set eth0 down
$ sudo ip link set eth0 up
  1. Restart the networking.service daemon

$ sudo systemctl restart networking.service

Windows

PS> ipconfig /all

Look for the paragraph where the client interface is configured (eg. Ethernet 8)

Ethernet adapter Ethernet 8
Connection-specific DNS suffix .: ...
Description ....................: ...
Physical Address ...............: ...
DHCP Enabled....................: Yes
Autoconfiguration Enabled.......: Yes
IPV4 Address....................: 88.88.88.xxx(Preferred)
Subnet Mask.....................: 255.255.255.0
Lease Obtained..................: ...
Lease Expires...................: ...
Default Gateway.................: 88.88.88.88
DHCP Server.....................: 88.88.88.88
DNS Server......................: 88.88.88.88
... 

The IPV4 address value displayed should be within the range of the DHCP pool range defined in the DHCP server configuration. The default gateway, DHCP server and DNS server entries should be the IP address of the DHCP server.

Troubleshooting on Windows

Reset the lease and request for a new IP address via a DHCP query:

PS> ipconfig /release [iface]
PS> ipconfig /renew [iface]

# eg. on interface "Ethernet"
PS> ipconfig /release "Ethernet"
PS> ipconfig /renew "Ethernet"
PreviousservicesNexthostapd

Last updated 1 month ago

🔫