• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
KaliTut

KaliTut

Kali Linux tutorial and Linux system tips

  • Home
  • Raspberry Pi
  • Privacy Policy
  • About us

Setup DNSMASQ as a DHCP server

Last Updated on May 30, 2020 by Kalitut 2 Comments

Setup Raspberry Pi DNSMASQ as a DHCP server

DNSMASQ as a DHCP server

“dnsmasq” refers to itself as “A lightweight DHCP and caching DNS server”. “Dnsmasq” is a very versatile daemon. In addition to being a DHCP server, it can also be used to provide DNS services (DNS forwarders) and IPv6 router advertisements.
Preparing to operate a DHCP server

  • Set IPv4 address range
  • Set subnet mask and default gateway
  • Set DNS server
  • Set lease time
  • Alternative: Setup ISC DHCP server

Note: Name of the network interfaces
Since Raspbian Stretch, the Ethernet and WLAN network interfaces have different names. So no longer “eth0” and “wlan0”, but “enx …” and “wlx …”. This concerns USB-connected network adapters whose names differ from the designations mentioned here. This means that one must first determine the individual name or change the naming to the old method.

  • Change Raspbian Stretch network interfaces

Important: Static IPv4 configuration
It makes sense that the relevant interface with the DNSMASQ should serve the IP network with a static IPv4 configuration.
It is important that the IPv4 configuration is bound to the relevant interface, even if there is no physical connection to the network.

Note: It is recommended to make the IPv4 configuration via the file “/etc/network/interfaces”.

  • Static IPv4 address for Raspbian Jessie and Stretch

Setup DNSMASQ
First we install the “dnsmasq” daemon.

sudo apt-get install dnsmasq

Then we continue with the configuration. Before we save the default configuration file and create a new one.

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf_old
sudo nano /etc/dnsmasq.conf

There we enter the following lines as minimal configuration:

# DHCP server active for WLAN interface
interface = wlan0


# DHCP server not active for existing network
no-dhcp-interface = eth0


# IPv4 address range and lease time
dhcp-range = 192.168.1.100,192.168.1.150,24h


# DNS
dhcp-option = option: dns-server 192.168.1.1

Here the DHCP server and the DNS forwarding for the network interface “wlan0” is activated and for the interface “eth0” only DNS, but no DHCP is served. In addition, it is specified that in the WLAN, the IPv4 addresses are assigned from 192.168.1.100 to 192.168.1.150 for the clients and the address of the DNS server is specified.

Test configuration
Before commissioning, it is recommended to test the configuration.

dnsmasq --test -C /etc/dnsmasq.conf

The syntax check should succeed with “OK”.

Enable DNSMASQ
Restart DNSMASQ:

sudo systemctl restart dnsmasq

Show DNSMASQ status:

sudo systemctl status dnsmasq

Start DNSMASQ at system startup:

sudo systemctl enable dnsmasq

Troubleshooting
If it is not quite clear if and how “dnsmasq” distributes the IPv4 addresses, you can show the clients’ communication with the DHCP server:

sudo dnsmasq -dd -C /etc/dnsmasq.conf

You can see the lease file here:

cat /var/lib/misc/dnsmasq.leases

Filed Under: Raspberry Pi Tagged With: DNSMASQ

Comments

  1. Richard Lewis says

    December 19, 2021 at 12:30 pm

    Just used your config file with minor mods. It produced a syntax error for the DNS option. There should be no space between “option:” and “dns-server” and “dns-server” should be followed by a comma. So the line should read:

    dhcp-option = option:dns-server, 192.168.1.1

    Reply
  2. Richard Lewis says

    December 19, 2021 at 12:44 pm

    Just used your config file with minor mods. It produced a syntax error for the DNS option. There should be no space between “option:” and “dns-server” and “dns-server” should be followed by a comma. So the line should read:

    dhcp-option = option:dns-server, 192.168.1.1

    You’ve also missed out the netmask from the dhcp-range. It should be:

    dhcp-range = 192.168.1.100, 192.168.1.150, 255.255.255.0, 24h

    dnsmasq doesn’t start its dhcp server without it.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow us

  • Facebook
  • Twitter
  • YouTube

Categories

  • Android pentesting tools
  • Arduino
  • Books
  • Darknet
  • database
  • General
  • Github Tools
  • Hacking
  • Kali Linux
  • Linux
  • Linux Commands
  • Network Administrator
  • Penetration Testing
  • Penetration Testing Tools
  • PowerShell
  • Raspberry Pi
  • resources
  • Review
  • Termux
  • Tutorials
  • Ubuntu
  • Uncategorized
  • Video Tutorials
  • vmware
  • WiFi Adapter
  • WiFi Pentesting
  • Wireless Router
  • Wireshark

Recent Posts

  • Hijacked Wi-Fi? Thorough explanation of hacking techniques
  • Windows PowerShell tutorial for beginners
  • Learn to Hack Steps from Beginner to Hacker
  • PowerShell Tutorial – GUIDE introduction with basics
  • Top Hacking Tools
  • Home
  • About us
  • Privacy Policy
  • Affiliate disclaimer

Copyright © 2023