Monday, 3 March 2014

Ubuntu Server: DHCP Server

I've implemented a DHCP server to work around the managed router (for internet access) that we have, which acts as the DHCP server.

All I had to do is make the interface (on my switch) to the router an untrusted port (to block DHCP) and make the interface to my DHCP server a trusted port.

Enter the following command in a terminal;

  • sudo apt-get install isc-dhcp-server


Edit the following file to your needs;


  • nano /etc/dhcp/dhcpd.conf



Example:

-------------------------------------------------------------------------------------------

default-lease-time 604800;
max-lease-time 691200;

subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.1 192.168.1.200;
    option routers 192.168.1.254;
    option domain-name-servers 8.8.8.8, 8.8.4.4;
    option domain-name "SAMBA.LOCAL";
    }

host NETGEARGS724T {
        hardware ethernet 08:BD:43:B9:8D:E4;
        fixed-address 192.168.1.250;
}

host CISCOGAIA {
        hardware ethernet 5C:A4:8A:75:71:D5;
        fixed-address 192.168.1.252;
}

host CISCOEROS {
        hardware ethernet 5C:A4:8A:75:74:36;
        fixed-address 192.168.1.251;
}

host CISCOROUTER {
        hardware ethernet 00:14:F2:75:D6:9B;
        fixed-address 192.168.1.254;
}

host IPPHONE {
    hardware ethernet C4:71:FE:C6:43:A6;
    fixed-address 192.168.1.240;
}

host IPPhone1 {
        hardware ethernet 3C:CE:73:D4:DF:57;
        fixed-address 192.168.1.241;
}

host IPPhone2 {
        hardware ethernet 3C:CE:73:D3:33:01;
        fixed-address 192.168.1.242;
}

host IPPhone3 {
        hardware ethernet 3C:CE:73:D3:0C:33;
        fixed-address 192.168.1.243;
}

host IPPhone4 {
        hardware ethernet CC:EF:48:5A:98:81;
        fixed-address 192.168.1.244;
}

host IPPhone5 {
        hardware ethernet 3C:CE:73:D3:A5:09;
        fixed-address 192.168.1.245;
}

host IPPhone6 {
        hardware ethernet C4:71:FE:C6:43:41;
        fixed-address 192.168.1.239;
}

host IPPhone7 {
        hardware ethernet C4:71:FE:C6:43:66;
        fixed-address 192.168.1.238;
}

host IPPhone8 {
        hardware ethernet 44:D3:CA:78:85:23;
        fixed-address 192.168.1.237;
}

host IPPhone9 {
        hardware ethernet C4:71:FE:C6:3F:43;
        fixed-address 192.168.1.236;
}

host IPPhone10 {
        hardware ethernet 3C:CE:73:D3:32:FF;
        fixed-address 192.168.1.235;
}

host IPPhone11 {
        hardware ethernet 44:D3:CA:78:5C:9C;
        fixed-address 192.168.1.234;
}

host IPPhone12 {
        hardware ethernet C4:71:FE:C6:43:A4;
        fixed-address 192.168.1.233;
}

host IPPhone13 {
        hardware ethernet 3C:CE:73:D3:0B:E9;
        fixed-address 192.168.1.232;
}

host IPPhone14 {
        hardware ethernet 50:3D:E5:0F:6B:0D;
        fixed-address 192.168.1.231;
}

host IPPhone15 {
        hardware ethernet C4:64:13:3C:01:20;
        fixed-address 192.168.1.230;
}

host IPPhone16 {
        hardware ethernet C4:71:FE:C6:43:AC;
        fixed-address 192.168.1.229;
}

host DHCP {
        hardware ethernet 00:0F:Fe:74:50:DC;
        fixed-address 192.168.1.249;
}

authoritative;

-------------------------------------------------------------------------------------------

To restart the service, use the following command;

  • sudo /etc/init.d/isc-dhcp-server restart
You can monitor leases in the following file;

  • nano /var/lib/dhcp/dhcpd.leases
Or use similar commands like the one below;

  • grep "^lease" /var/lib/dhcp/dhcpd.leases |sort |uniq |wc -l

Sources;
https://help.ubuntu.com/12.04/serverguide/dhcp.html
http://tldp.org/HOWTO/DHCP/x369.html#DHCPSERVER
http://serverfault.com/questions/289831/exclude-ip-address-from-dhcp-pool

No comments:

Post a Comment