If you have a Linux system and want to create a local network with DHCP services and internet access for Wi-Fi clients, you’re in the right place. In this guide, we’ll walk you through the steps of configuring your Linux machine to act as a DHCP server using dnsmasq and enable internet access for devices connected via Wi-Fi.

Step 1: Install dnsmasq

Firstly, ensure that dnsmasq is installed on your Linux system. Open a terminal and run the following commands:

				
					sudo apt update 
sudo apt install dnsmasq
				
			

Step 2: Configure dnsmasq

Now, it’s time to configure dnsmasq. Open the configuration file in a text editor:

				
					sudo nano /etc/dnsmasq.conf
				
			

Add or modify the following lines:

				
					interface=<YourEthernetInterface> dhcp-range=10.10.0.1,10.10.0.254,255.255.255.0,12h
				
			

Replace <YourEthernetInterface> with the name of your Ethernet interface (e.g., eth0). Save the file.

Step 3: Enable IP Forwarding and Set Up NAT

Next, enable IP forwarding and set up Network Address Translation (NAT). Edit the sysctl configuration:

				
					sudo nano /etc/sysctl.conf
				
			

Uncomment the line net.ipv4.ip_forward=1. Apply the changes:

				
					sudo sysctl -p
				
			

Configure iptables for NAT:

				
					sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE sudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
				
			

Save iptables rules and restart services:

				
					sudo sh -c "iptables-save > /etc/iptables/rules.v4" sudo service dnsmasq restart sudo systemctl restart networking
				
			

Step 4: Verify Configuration

Ensure that your Wi-Fi interface is configured to use DHCP and check the connectivity of devices connected to the local network.

Congratulations! Your Linux system is now serving as a DHCP server and providing internet access to devices connected via Wi-Fi.