配置如下
R1配置:
Router#conf
Router_config#hostname R1
R1_config#int g0/1
R1_config_g0/1#ip add 192.168.10.1 255.255.255.252
R1_config_g0/1#no sh
R1_config_g0/1#int g0/0
R1_config_g0/0#no sh
R1_config_g0/0#int g0/0.10
R1_config_g0/0.10#encapsulation dot1Q 10
R1_config_g0/0.10#ip add 172.16.10.1 255.255.255.0
R1_config_g0/0.10#no sh
R1_config_g0/0.10#int g0/0.20
R1_config_g0/0.20#encapsulation dot1Q 20
R1_config_g0/0.20#ip add 172.16.20.1 255.255.255.0
R1_config_g0/0.20#no sh
R1_config_g0/0.20#exit
R1_config#router ospf 1
R1_config_ospf_1#network 192.168.10.0 255.255.255.252 area 0
R1_config_ospf_1#network 172.16.10.0 255.255.255.0 area 0
R1_config_ospf_1#network 172.16.20.0 255.255.255.0 area 0
R1_config_ospf_1#exit
R1_config#ip forward-protocol udp bootps
R1_config#int g0/0.10
R1_config_g0/0.10#ip helper-address 192.168.10.2
R1_config_g0/0.10#int g0/0.20
R1_config_g0/0.20#ip helper-address 192.168.10.2
R1_config_g0/0.20#end
R1#wr
R2配置:
Router#conf
Router_config#hostname R2
R2_config#int g0/1
R2_config_g0/1#ip add 192.168.10.2 255.255.255.252
R2_config_g0/1#no sh
R2_config_g0/1#exit
R2_config#router ospf 1
R2_config_ospf_1#network 192.168.10.0 255.255.255.252 area 0
R2_config_ospf_1#exit
R2_config#ip dhcpd enable
R2_config#ip dhcpd pool 10
R2_config_dhcp#network 172.16.10.0 255.255.255.0
R2_config_dhcp#default-router 172.16.10.1
R2_config_dhcp#range 172.16.10.2 172.16.10.254
R2_config_dhcp#dns 8.8.8.8
R2_config_dhcp#lease 8 0 0
R2_config_dhcp#exit
R2_config#ip dhcpd pool 20
R2_config_dhcp#network 172.16.20.0 255.255.255.0
R2_config_dhcp#default-router 172.16.20.1
R2_config_dhcp#range 172.16.20.2 172.16.20.254
R2_config_dhcp#dns 8.8.8.8
R2_config_dhcp#lease 8 0 0
R2_config_dhcp#end
R2#wr
SWA配置:
DCWS-6028#conf
DCWS-6028(config)#hostname SWA
SWA(config)#vlan 10;20
SWA(config)#int e1/0/1
SWA(config-if-ethernet1/0/1)#sw acc vlan 10
SWA(config-if-ethernet1/0/1)#int e1/0/2
SWA(config-if-ethernet1/0/2)#sw acc vlan 20
SWA(config)#int e1/0/24
SWA(config-if-ethernet1/0/24)#sw mo tr
SWA(config-if-ethernet1/0/24)#end
SWA#wr
验证PC1、PC2自动获取IP地址:
PC1获取的IP
PC2获取的IP