Configuring DHCP server
If you have two network cards in your ubuntu server you need to select which interface you want to use for DHCP server listening.By default it listens to eth0.
You can change this by editing /etc/default/dhcp3-server file
sudo vi /etc/default/dhcp3-server
Find this line
INTERFACES="eth0"
Replace with the following line
INTERFACES="eth1"
Save and exit.This is optional. COOL~~
Next you need to make a backup copy of /etc/dhcp3/dhcpd.conf file
cp /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.back
Edit /etc/dhcp3/dhcpd.conf file using the following command
sudo vi /etc/dhcp3/dhcpd.conf
Using address pool method
You need to change the following sections in /etc/dhcp3/dhcpd.conf file
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.254;
option domain-name-servers 192.168.1.1, 192.168.1.2;
option domain-name ¡°yourdomainname.com¡±;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.200;
}
This will result in the DHCP server giving a client an IP address from the range 192.168.1.10-192.168.1.200 . It will lease an IP address for 600 seconds if the client doesn¡¯t ask for a specific time frame. Otherwise the maximum (allowed) lease will be 7200 seconds. The server will also ¡°advise¡± the client that it should use 255.255.255.0 as its subnet mask, 192.168.1.255 as its broadcast address, 192.168.1.254 as the router/gateway and 192.168.1.1 and 192.168.1.2 as its DNS servers.
Using MAC address method
This method is you can reserver some of the machines or all the machines with fixed ip address.In the following example i am using fixed ip address for server1,server2,printer1 and printer2
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.254;
option domain-name-servers 192.168.1.1, 192.168.1.2;
option domain-name ¡°yourdomainname.com¡±;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.200;
}
host server1 {
hardware ethernet 00:1b:63:ef:db:54;
fixed-address 192.168.1.20;
}
host server2 {
hardware ethernet 00:0a:95:b4:d4:b0;
fixed-address 192.168.1.21;
}
host printer1 {
hardware ethernet 00:16:cb:aa:2a:cd;
fixed-address 192.168.1.22;
}
host printer2 {
hardware ethernet 00:0a:95:f5:8f:b3;
fixed-address 192.168.1.23;
}
Now you need to restart dhcp server using the following command
sudo /etc/init.d/dhcp3-server restart
Configure Ubuntu DHCP Client
If you want to configure your ubuntu desktop as DHCP client following this procedure
You need to open /etc/network/interfaces file
sudo vi /etc/network/interfaces
make sure you have the following lines (eth0 is an example)
iface eth0 inet dhcp
iface lo inet loopback
Save and exit the file
You need to restart networking services using the following command
sudo /etc/init.d/networking restart
How to find DHCP server IP address
You need to use the following commands
sudo dhclient
or
tail -n 15 /var/lib/dhcp3/dhclient.*.leases