一、概况
DHCP服务器ip地址:192.168.10.253
主机名:dhcpser.tarena.com
默认网关:192.168.10.254
DHCP地址池:
192.168.10.50 192.168.10.100;
192.168.10.120 192.168.10.200;
实验前关闭iptables和selinux
二、步骤
1.配置dhcp服务器的ip地址
(1)配置ip地址
[root@rhel5-1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
[root@rhel5-1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet
IPADDR=192.168.10.253
NETMASK=255.255.255.0
(2)添加dna映射
[root@rhel5-1 ~]# vim /etc/hosts
[root@rhel5-1 ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.10.253 dhcpser.tarena.com dhcpser
(3)修改主机名,添加静态路由
[root@rhel5-1 ~]# vim /etc/sysconfig/network
[root@rhel5-1 ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=dhcpser.tarena.com
GATEWAN=192.168.10.254
(4)重启network服务
[root@rhel5-1 ~]# /etc/init.d/network restart
[root@rhel5-1 ~]# chkconfig network on
(5)验证
[root@rhel5-1 ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:8E:66:6D
inet addr:192.168.10.253 Bcast:192.168.10.255 Mask:255.255.255.0
[root@rhel5-1 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.10.254 0.0.0.0 UG 0 0 0 eth0
[root@dhcpser ~]# hostname
dhcpser.tarena.com
root@dhcpser ~]# ping dhcpser.tarena.com
PING dhcpser.tarena.com (192.168.10.253) 56(84) bytes of data.
64 bytes from dhcpser.tarena.com (192.168.10.253): icmp_seq=1 ttl=64 time=0.040 ms
64 bytes from dhcpser.tarena.com (192.168.10.253): icmp_seq=5 ttl=64 time=0.032 ms
64 bytes from dhcpser.tarena.com (192.168.10.253): icmp_seq=6 ttl=64 time=0.027 ms
--- dhcpser.tarena.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5000ms
rtt min/avg/max/mdev = 0.027/0.032/0.040/0.004 ms
2.安装dhcp服务
[root@dhcpser Server]# rpm -q dhcp
package dhcp is not installed
[root@dhcpser Server]# mount /dev/cdrom /media/
[root@dhcpser Server]# cd /media/Server/
[root@dhcpser Server]# rpm -ivh dhcp-3.0.5-33.el5_9.x86_64.rpm
[root@dhcpser Server]# rpm -q dhcp
dhcp-3.0.5-33.el5_9
3.修给dhcp配置文件
[root@dhcpser Server]# vim /etc/dhcpd.conf
[root@dhcpser Server]# cat /etc/dhcpd.conf
ddns-update-style interim;
subnet 192.168.10.0 netmask 255.255.255.0 {
option routers 192.168.10.254;
option subnet-mask 255.255.255.0;
option domain-name "tarena.com";
option domain-name-servers 192.168.10.253;
range dynamic-bootp 192.168.10.50 192.168.10.100;
range dynamic-bootp 192.168.10.120 192.168.10.200;
default-lease-time 28800;
max-lease-time 86400;
#host win7 {
#hardware ethernet 12:34:56:78:AB:CD;
#fixed-address 207.175.42.254;
#}
}
4.启动dhcp服务
root@dhcpser Server]# /etc/init.d/dhcpd restart
启动 dhcpd: [确定]
[root@dhcpser Server]# chkconfig dhcpd on
[root@dhcpser Server]# netstat -ln | grep :67
udp 0 0 0.0.0.0:67 0.0.0.0:*
[root@dhcpser Server]# /etc/init.d/dhcpd configtest
Syntax: OK
5.客户端的测试
(1)修改客户端网卡配置文件
[root@localhost ~ 07:16 #75]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost ~ 07:17 #76]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
TYPE=Ethernet
BOOTPROTO=dhcp
ONBOOT=yes
(2)重启客户端network,查看IP地址
[root@localhost ~ 07:18 #80]# /etc/init.d/network restart
[root@localhost ~ 07:18 #81]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:CD:3E:5C
inet addr:192.168.10.200 Bcast:192.168.10.255 Mask:255.255.255.0
(3)查看地址解析,给客户端配置固定地址
[root@dhcpser ~]# arp -an
? (192.168.10.254) at <incomplete> on eth0
? (192.168.10.200) at 00:0C:29:CD:3E:5C [ether] on eth0
[root@dhcpser ~]# vim /etc/dhcpd.conf
[root@dhcpser ~]# cat /etc/dhcpd.conf
ddns-update-style interim;
subnet 192.168.10.0 netmask 255.255.255.0 {
option routers 192.168.10.254;
option subnet-mask 255.255.255.0;
option domain-name "tarena.com";
option domain-name-servers 192.168.10.253;
range dynamic-bootp 192.168.10.50 192.168.10.100;
range dynamic-bootp 192.168.10.120 192.168.10.200;
default-lease-time 28800;
max-lease-time 86400;
host linux {
hardware ethernet 00:0C:29:CD:3E:5C;
fixed-address 192.168.10.10;
}
}
(4)重启服务
[root@dhcpser ~]# /etc/init.d/dhcpd restart
(5)客户端重启network并查看ip地址
[root@localhost ~ 07:33 #83]# /etc/init.d/network restart
[root@localhost ~ 07:33 #84]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:CD:3E:5C
inet addr:192.168.10.10 Bcast:192.168.10.255 Mask:255.255.255.0