(保證虛擬機兩張網卡都相同,這裏採用的是NAT模式)centos
1. 安裝DHCP 服務端服務器
[root@xuegod175 ~]# rpm -ivh/media/CentOS_6.5_Final/Packages/dhcp-common-4.1.1-38.P1.el6.centos.x86_64.rpmdom
Preparing... ########################################### [100%]ide
packagedhcp-common-12:4.1.1-38.P1.el6.centos.x86_64 is already installedoop
[root@xuegod175 ~]# rpm -ivh/media/CentOS_6.5_Final/Packages/dhcp-測試
dhcp-4.1.1-38.P1.el6.centos.x86_64.rpm dhcp-common-4.1.1-38.P1.el6.centos.x86_64.rpmspa
[root@xuegod175 ~]# rpm -ivh/media/CentOS_6.5_Final/Packages/dhcp-4.1.1-38.P1.el6.centos.x86_64.rpmrest
Preparing... ########################################### [100%]router
1:dhcp ########################################### [100%]server
[root@xuegod175 ~]# rpm -ivh/media/CentOS_6.5_Final/Packages/dhclient-4.1.1-38.P1.el6.centos.x86_64.rpm
Preparing... ########################################### [100%]
packagedhclient-12:4.1.1-38.P1.el6.centos.x86_64 is already installed
2. 拷貝配置文件
[root@xuegod175 ~]# cp/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
cp: overwrite `/etc/dhcp/dhcpd.conf'?yes
3. 修改主要配置文件
[root@xuegod175 ~]# cat/etc/dhcp/dhcpd.conf
subnet 192.168.42.0 netmask255.255.255.0{ (192.168.42.0) 網段 (255.255.255.0)子網掩碼
range 192.168.42.100 192.168.42.200; #表示的是地址池
option domain-name-servers 192.168.42.2; #DNS地址
option domain-name"xuegod.cn";
option routers 192.168.42.2; #網關(注意:這裏的網關在虛擬機中要查看NAT 裏面設置的網關要一致)
option broadcast-address 192.168.42.255;#廣播地址
default-lease-time 600; 最短租期
max-lease-time 7200; 最長租期
}
4. 客戶端進行測試
客戶端機器須要把IP 地址獲取方式改爲自動獲取方式 重啓網卡進行測試
[root@xuegod176~]# /etc/init.d/network restart
Shutting downinterface eth0: Device state: 3(disconnected)
[ OK ]
Shutting downloopback interface: [ OK ]
Bringing uploopback interface:
[ OK ]
Bringing upinterface eth0: Active connection state:activated
Activeconnection path: /org/freedesktop/NetworkManager/ActiveConnection/4 [ OK ]
經測試:客戶端可以正常獲取到ip地址
查看網關
[root@xuegod176 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.42.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1
0.0.0.0 192.168.42.2 0.0.0.0 UG 0 0 0 eth1 #網關正確
查看DNS
[root@xuegod176 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
domain xuegod.cn
search xuegod.cn cn
nameserver 192.168.42.2 #DNS 正確