[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 client will have the same gateway point to Squid Server. In my case i installed Proxy server (Squid) and DHCP server is on the same machine. But if you want to install in separate machine, you still can use this tutorial. The use of DHCP here is to point all of your client gateway to proxy server so the squid can work properly.

I have a case example like this: i have a PC as a router that i installed squid proxy and dhcp server. My PC have 2 network cards eth0 connect to local Lan, and eth1 connect to a modem that connect 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. And see if your client computer can get the ip from the dhcp and also test if the proxy server function properly. Cheers and Good luck.

Comments

  1. Tynkor says:

    Hi Ivan , i follow you all the way to set up the transparent proxy and it works fine after i set up gateway and DNS ip in client server.

    but now i try to avoid setup gateway&DNS on client and follow this guide, it not work for me.

    my setup: server pc with 2 Eth card, eth0(to lan) ip 192.168.5.1 , eth1 (to other router which connected to internet) ip 192.168.1.7

    DHCP setup :

    default-lease-time 86400;
    max-lease-time 604800;

    subnet 192.168.5.0 netmask 255.255.255.0 {

    option domain-name-servers 192.168.5.1;
    option domain-name "yourdomain.com";

    range dynamic-bootp 192.168.5.101 192.168.5.200;
    option routers 192.168.5.1;
    }

    please help.

    • Anonymous says:

      Please check if any device that act as DHCP server too in your local area.
      Based on my experience, i have a device like Wireless Router.
      Please check other devices.
      Cheers.

  2. Tynkor says:

    Hi Ivan , i follow you all the way to set up the transparent proxy and it works fine after i set up gateway and DNS ip in client server.

    but now i try to avoid setup gateway&DNS on client and follow this guide, it not work for me.

    my setup: server pc with 2 Eth card, eth0(to lan) ip 192.168.5.1 , eth1 (to other router which connected to internet) ip 192.168.1.7

    DHCP setup :

    default-lease-time 86400;
    max-lease-time 604800;

    subnet 192.168.5.0 netmask 255.255.255.0 {

    option domain-name-servers 192.168.5.1;
    option domain-name "yourdomain.com";

    range dynamic-bootp 192.168.5.101 192.168.5.200;
    option routers 192.168.5.1;
    }

    please help.

    • Ivan says:

      Please check if any device that act as DHCP server too in your local area.
      Based on my experience, i have a device like Wireless Router.
      Please check other devices.
      Cheers.

  3. Tynkor says:

    woot , thank for the fast reply.

    my server pc eth0 ip 192.168.5.1 connected to a wireless router but i disable the router DHCP service so it should be act like a switch now.

    my server pc eth1 ip 192.168.1.7 connected to a DHCP router which the wanl connected to Internet.

    my squid listen at 192.168.1.7 8080 as trasparent

    i used your ip table script and tested fine before the server pc runs DHCP server (when i testing your ip table scrpt , my eth0 connected router act like DHCP and i need to set my client pc TCP/IP tap to use the eth0 ip as gateway , and have to put my ISP provided DNS ip to able to access internet by proxy)

    my DHCP server picked eth0 as the device that runs the DHCP setting.

    my client pc can ping server pc's eth1 network ip like 192.168.1.xxx and also 192.168.5.1

    my client pc's default gateway now is auto set to 192.168.5.1.

    let me know if you need any other details.

    Thanks again =)

  4. Tynkor says:

    woot , thank for the fast reply.

    my server pc eth0 ip 192.168.5.1 connected to a wireless router but i disable the router DHCP service so it should be act like a switch now.

    my server pc eth1 ip 192.168.1.7 connected to a DHCP router which the wanl connected to Internet.

    my squid listen at 192.168.1.7 8080 as trasparent

    i used your ip table script and tested fine before the server pc runs DHCP server (when i testing your ip table scrpt , my eth0 connected router act like DHCP and i need to set my client pc TCP/IP tap to use the eth0 ip as gateway , and have to put my ISP provided DNS ip to able to access internet by proxy)

    my DHCP server picked eth0 as the device that runs the DHCP setting.

    my client pc can ping server pc's eth1 network ip like 192.168.1.xxx and also 192.168.5.1

    my client pc's default gateway now is auto set to 192.168.5.1.

    let me know if you need any other details.

    Thanks again =)

  5. Tynkor says:

    base on the logic , it should be working fine now when i set my server pc eth0 to the gateway IP of the lan. then the ip table script should handle on eth0 packet data thinggy like the testing with out DHCP server but use router's DHCP service with client pointed gateway ……. but it just not working for me ==" should i do something on server pc network configure to setup some routing and gateway ?

    • Anonymous says:

      Did you install Bind9 DNS server?
      Install it and bypass your DNS to your DNS provided by your ISP.
      My script is working fine with me. I'm using it too.
      Let me know if install Bind is working with you.
      Thanks

  6. Tynkor says:

    base on the logic , it should be working fine now when i set my server pc eth0 to the gateway IP of the lan. then the ip table script should handle on eth0 packet data thinggy like the testing with out DHCP server but use router's DHCP service with client pointed gateway ……. but it just not working for me ==" should i do something on server pc network configure to setup some routing and gateway ?

    • Ivan says:

      Did you install Bind9 DNS server?
      Install it and bypass your DNS to your DNS provided by your ISP.
      My script is working fine with me. I'm using it too.
      Let me know if install Bind is working with you.
      Thanks

  7. Tynkor says:

    well , after some research , and reverse all and back to your [HowTo] Install and Configure Squid as Transparent Proxy post and i found that with out install bind9 , i can use gateway IP put at DNS there and the transparent proxy works fine. But after switch to using DHCP server and follow all your guide. It just not working. But, i can ping any of the eth1 ip and able to use them as proxy IP on my client pc to online ….

    I'm new to DNS area, and I have no idea what to do with bind9 after install.

    Can you make a quick guide on it? Or maybe the problem not effected by NDS?

  8. Tynkor says:

    well , after some research , and reverse all and back to your [HowTo] Install and Configure Squid as Transparent Proxy post and i found that with out install bind9 , i can use gateway IP put at DNS there and the transparent proxy works fine. But after switch to using DHCP server and follow all your guide. It just not working. But, i can ping any of the eth1 ip and able to use them as proxy IP on my client pc to online ….

    I'm new to DNS area, and I have no idea what to do with bind9 after install.

    Can you make a quick guide on it? Or maybe the problem not effected by NDS?

  9. Tynkor says:

    I dont know why it just can't works when i make the server pc as DHCP router ……

    I found another way so make it works. it's actually using the old gateway steps but just set the router bind server pc's mac address to ip xxx.xxx.xxx.1 (which is eth0 ip) and the router ip also set to xxx.xxx.xxx.1 so that all client pc passby this router will using the ip as default gateway …..

    dont know why i set all the things at the server pc it just not work it's totally same logic ><"

  10. Tynkor says:

    I dont know why it just can't works when i make the server pc as DHCP router ……

    I found another way so make it works. it's actually using the old gateway steps but just set the router bind server pc's mac address to ip xxx.xxx.xxx.1 (which is eth0 ip) and the router ip also set to xxx.xxx.xxx.1 so that all client pc passby this router will using the ip as default gateway …..

    dont know why i set all the things at the server pc it just not work it's totally same logic ><"

  11. Tynkor says:

    Any way, Ivan, thank you so much for the guide, it really do help =)

  12. Tynkor says:

    Any way, Ivan, thank you so much for the guide, it really do help =)

  13. denda says:

    dear ivan, can you help me? please. Hmm i'm newbe to use linux. Now i'm studying linux and i can't install dhcp-server on ubuntu 9.10. And the result is: E: couldn't find package dhcp-server…

  14. denda says:

    dear ivan, can you help me? please. Hmm i'm newbe to use linux. Now i'm studying linux and i can't install dhcp-server on ubuntu 9.10. And the result is: E: couldn't find package dhcp-server…

Give me your feedback

This site uses Akismet to reduce spam. Learn how your comment data is processed.