Dhcp中继
配置运行环境
1. DHCP server 在Linux 192.168.10.100上
2. router 在linux上配置relay
3. 区域192.168.20.x 192.168.30.x通过router向DHCP server申请地址
l Linux中必须做Dhcp服务器的作用域,即服务器必须在作用域中,可以是空作用域
1.安装dhcp server
[root@localhost Server]# rpm -qa dhcp
dhcp- 3.0.5 -18.el5.i386.rpm dhcpv6-1.0.10-16.el5.i386.rpm
dhcp-devel- 3.0.5 -18.el5.i386.rpm dhcpv6-client-1.0.10-16.el5.i386.rpm
[root@localhost Server]# rpm -qa dhcp
[root@localhost Server]#
[root@localhost Server]# rpm -ivh dhcp- 3.0.5 -18.el5.i386.rpm
2.配置dhcpd.conf文件
[root@localhost ~]# vim /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
#定义区域192.168.20.0
subnet 192.168.20.0 netmask 255.255.255.0 {
option routers 192.168.20.254;--设置客户端的默认网关
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.20.1 192.168.20.10;
default-lease-time 21600;
max-lease-time 43200;
}
#定义区域192.168.30.0
subnet 192.168.30.0 netmask 255.255.255.0 {
option routers 192.168.30.254;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.30.1 192.168.30.10;
default-lease-time 21600;
max-lease-time 43200;
}
#定义区域192.168.10.0 dhcp server所在的区域,可以是空区域
subnet 192.168.10.0 netmask 255.255.255.0 {
}
#定义配置信息的参考模板可以从下面的文件读入
:r /usr/share/doc/dhcp- 3.0.5 /dhcpd.conf.sample
#检查配置信息是否有错
[root@localhost ~]# service dhcpd configtest
Syntax: OK
3.配置server的ip
[root@localhost Server] vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
IPADDR=192.168.10.100
NETWORK=255.255.255.0
GATEWAY=192.168.10.254
ONBOOT=yes
HWADDR=00:0c:29:7d:c7:28
[root@localhost Server]# service network restart.
4.启动dhcpd
[root@localhost ~]# chkconfig --list dhcpd
dhcpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@localhost ~]# chkconfig dhcpd on
[root@localhost ~]# chkconfig --list dhcpd
dhcpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
5.查看server的路由
[root@localhost ~]# 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@localhost ~]#
6.测试到达路由是否联通
[root@localhost ~]# ping 192.168.10.254
PING 192.168.10.254 (192.168.10.254) 56(84) bytes of data.
64 bytes from 192.168.10.254: icmp_seq=1 ttl=128 time=0.304 ms
[root@localhost ~]# ping 192.168.20.254
PING 192.168.20.254 (192.168.20.254) 56(84) bytes of data.
64 bytes from 192.168.20.254: icmp_seq=1 ttl=128 time=0.460 ms
[root@localhost ~]# ping 192.168.30.254
PING 192.168.30.254 (192.168.30.254) 56(84) bytes of data.
64 bytes from 192.168.30.254: icmp_seq=1 ttl=128 time=0.177 ms
[root@localhost ~]#
l 配置Linux relay
dhcrelay包含在dhcp- 3.0.5 -18.el5.i386.rpm
1. 安装dhcp server
[root@localhost Server]# rpm -qa dhcp
dhcp- 3.0.5 -18.el5.i386.rpm dhcpv6-1.0.10-16.el5.i386.rpm
dhcp-devel- 3.0.5 -18.el5.i386.rpm dhcpv6-client-1.0.10-16.el5.i386.rpm
[root@localhost Server]# rpm -qa dhcp
[root@localhost Server]#
[root@localhost Server]# rpm -ivh dhcp- 3.0.5 -18.el5.i386.rpm
2.配置dhcrelay文件
#查看dhcp安装包含的文件—包含dhcrelay
[root@localhost ~]# rpm -ql dhcp
/etc/dhcpd.conf
/etc/rc.d/init.d/dhcpd
/etc/rc.d/init.d/dhcrelay
/etc/sysconfig/dhcpd
/etc/sysconfig/dhcrelay
[root@localhost ~]# vim /etc/sysconfig/dhcrelay
INTERFACES="eth0 eth1 eth2"
DHCPSERVERS="192.168.10.100"
#netstat –tulpn |grep dhc
3.开启路由功能
[root@localhost ~]# vim /etc/sysctl.conf
--开启路由
net.ipv4.ip_forward = 1
--同步信息
[root@localhost ~]# sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 4294967295
kernel.shmall = 268435456
4.关闭DHCP服务,开启DHCP中继服务
[root@localhost ~]# chkconfig --list |grep dhc
dhcpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
dhcrelay 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@localhost ~]# chkconfig dhcpd off
[root@localhost ~]# chkconfig dhcrelay on
[root@localhost ~]# chkconfig --list |grep dhc
dhcpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
dhcrelay 0:off 1:off 2:on 3:on 4:on 5:on 6:off
5.如果客户端分配不到ip
[root@localhost ~]#service dhcrelay start
6.查看DHCP中继路由
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.20.0 0.0.0 .0 255.255.255.0 U 0 0 0 eth1
192.168.30.0 0.0.0 .0 255.255.255.0 U 0 0 0 eth2
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 eth2
[root@localhost ~]#
l 客户端获取地址
windows xp 和linux分别在vm3 vm2 获取地址
Vm2
Vm3