需求描述:
在网关主机中构建DHCP、DHCP中继服务器
1.为以下三个物理网段提供动态地址分配服务:
192.168.1.0/24
192.168.2.0/24
192.168.3.0/24
2.默认租约时间21600秒
3.最大租约时间43200秒
4.客户机使用的DNS服务器地址如下:
202.106.0.20
8.8.8.8
5.用于动态分配的IP 地址范围分别为:
192.168.1.100~192.168.1.200
192.168.2.100~192.168.2.200
192.168.3.100~192.168.3.200
网关主机各接口的IP地址作为对应网段的默认网关
实现思路:
1.确认服务器主机的网络地址配置正确
2.先配置好DHCP服务器
3.再配置DHCP中继服务器
验证实验结果
注意事项:
将虚拟机的内存设为256MB,进入字符模式,关闭不常用的系统服务程序
将DHCP服务器的默认网关指向DHCP中继服务器
GO
DHCP服务器的配置(网卡为vmnet2)
[root@dhcpserver ~]# service iptables stop
[root@dhcpserver ~]# setenforce 0
[root@dhcpserver ~]# cat/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
HWADDR=00:0c:29:b3:f2:f5
IPADDR=192.168.1.2
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
[root@dhcpserver ~]# service network restart
[root@dhcpserver ~]# ifconfig eth0
[root@dhcpserver ~]# yum -y install dhcp
[root@dhcpserver ~]# cp/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
[root@dhcpserver ~]# vim /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
default-lease-time 21600;
max-lease-time 43200;
optiondomain-name-servers 202.106.0.20,8.8.8.8;
optiondomain-name "Crushlinux.com";
subnet 192.168.1.0 netmask 255.255.255.0 {
optionrouters 192.168.1.1;
optionsubnet-mask 255.255.255.0;
rangedynamic-bootp 192.168.1.100 192.168.1.200;
}
subnet 192.168.2.0 netmask 255.255.255.0 {
optionrouters 192.168.2.1;
optionsubnet-mask 255.255.255.0;
range dynamic-bootp 192.168.2.100192.168.2.200;
}
subnet 192.168.3.0 netmask 255.255.255.0 {
optionrouters 192.168.3.1;
optionsubnet-mask 255.255.255.0;
rangedynamic-bootp 192.168.3.100 192.168.3.200;
}
[root@dhcpserver ~]# service dhcpd restart
[root@dhcpserver ~]# chkconfig dhcpd on
[root@dhcpserver ~]# ping 192.168.1.1
DHCP中继服务器的配置(共3个网卡,第一个:vmnet2,第二个:vmnet3,第四个:vmnet4)
[root@DHCRELAY ~]# service iptables stop
[root@DHCRELAY ~]# setenforce 0
[root@DHCRELAY ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0c:29:e0:f7:26
ONBOOT=yes
IPADDR=192.168.1.1
NETMASK=255.255.255.0
GATEWAY=192.168.1.2
[root@DHCRELAY ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=static
HWADDR=00:0c:28:e0:f7:33
ONBOOT=yes
IPADDR=192.168.2.1
NETMASK=255.255.255.0
[root@DHCRELAY ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
BOOTPROTO=static
HWADDR=00:0b:17:e0:f7:33
ONBOOT=yes
IPADDR=192.168.3.1
NETMASK=255.255.255.0
[root@DHCRELAY ~]# service network restart
[root@DHCRELAY ~]# ifconfig
[root@DHCRELAY ~]# ping 192.168.1.2
[root@DHCRELAY ~]# yum -y install dhcp
[root@DHCRELAY ~]# vim /etc/sysconfig/dhcrelay
INTERFACES="eth0 eth1 eth2"
DHCPSERVERS="192.168.1.2"
[root@DHCRELAY ~]# service dhcrelay start
[root@DHCRELAY ~]# service dhcrelay restart
[root@DHCRELAY ~]# chkconfig dhcrelay on
[root@DHCRELAY ~]# netstat –tulnp |grep dhcrelay
客户机测试
客户机网卡分别设置成vmnet2、vmnet3、vmnet4 获取IP地址进行测试
测试命令:
开始-->运行-->cmd
C:\Users\Crushlinux>cd \
C:\>ipconfig /release
C:\>ipconfig /renew