Tuesday, December 14, 2010

Configure DHCP Server on Linux

Server Part:
=========================
[root@rh5 ~]# rpm -q dhcp-3.0.5-23.el5_5.2
dhcp-3.0.5-23.el5_5.2

[root@rh5 ~]# vi /etc/dhcpd.conf
[root@rh5 ~]# cat /etc/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
#
ddns-update-style interim;
ignore client-updates;

subnet 192.168.1.0 netmask 255.255.255.0 {

# --- default gateway
range 192.168.1.200 192.168.1.210;
option routers 192.168.1.254;
option subnet-mask 255.255.255.0;

option nis-domain "lab.dbaglobe.com";
option domain-name "lab.dbaglobe.com";
option domain-name-servers 192.168.1.254;

# option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
}



[root@rh5 ~]# service dhcpd restart
Starting dhcpd: [ OK ]


Client Part:
=========================
[root@unknown-08-00-27-07-fa-07 ~]# cat /etc/dhclient.conf
# 192.168.1.254 is one of the DHCP Server in the local network
# After reject it, the dhcp network can use 192.168.1.100 as DHCP Server
reject 192.168.1.254;
interface "eth0" {
send host-name "vmxdb02.lab.dbaglobe.com";
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, host-name;
require subnet-mask, domain-name-servers;
}

[root@unknown-08-00-27-07-fa-07 ~]# dhclient
Internet Systems Consortium DHCP Client V3.0.5-RedHat
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/

Listening on LPF/eth0/08:00:27:07:fa:07
Sending on LPF/eth0/08:00:27:07:fa:07
Sending on Socket/fallback
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPACK from 192.168.1.254 rejected.
DHCPACK from 192.168.1.100
bound to 192.168.1.210 -- renewal in 19873 seconds.

[root@unknown-08-00-27-07-fa-07 ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 08:00:27:07:FA:07
inet addr:192.168.1.210 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe07:fa07/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:15501 errors:0 dropped:0 overruns:0 frame:0
TX packets:2505 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1015295 (991.4 KiB) TX bytes:326697 (319.0 KiB)