[HowTo] Install DHCP Server On Ubuntu

To complete my guide “How To Install And Configure Squid as Transparent Proxy“, you will need a DHCP server installed on the server as well. So all of your clients will have the same gateway pointing to the Squid server. In my case I installed the proxy server (Squid) and DHCP server on the same machine. But if you want to install them on separate machines, you can still use this tutorial. The use of DHCP here is to point all of your client gateways to the proxy server so that Squid can work properly.

I have a case example like this: I have a PC as a router on which I installed Squid proxy and DHCP server. My PC has 2 network cards — eth0 connected to the local LAN, and eth1 connected to a modem that connects to the Internet. My eth0 address is 172.16.144.1 (this would be the gateway IP).

Install DHCP Server On Ubuntu

1. Open your terminal and type this command:

sudo apt-get install dhcp3-server

2. Open file /etc/default/dhcp3-server with this command:

vim /etc/default/dhcp3-server

Find this line INTERFACES="eth0"
Change that line according to your network card; in my case it is eth0 so I don’t have to change that.

3. Open file /etc/dhcp3/dhcpd.conf with this command:

vim /etc/dhcp3/dhcpd.conf

Make the configuration like below:

subnet 172.16.144.0 netmask 255.255.255.0 {
range 172.16.144.100 172.16.144.200;
option domain-name-servers 172.16.144.1;
option domain-name "yourdomain.com";
option routers 172.16.144.1;
option subnet-mask 255.255.255.0;
option broadcast-address 172.16.144.255;
default-lease-time 21600;
max-lease-time 43200;
}

Save the file and close.

4. Restart your DHCP server with this command:

/etc/init.d/dhcp3-server restart

It’s done. Now test your client. See if your client computer can get the IP from the DHCP and also test if the proxy server functions properly. Cheers and good luck.