三层交换及DHCP中继配置
B-SW-2L二层交换机配置:
1,模拟器开启后基本配置
Router#conf t
Router(config)#ho B-SW-2L
B-SW-2L(config)#no ip do lo
B-SW-2L(config)#no ip routing
B-SW-2L(config)#lin c 0
B-SW-2L(config-line)#no exec-t
B-SW-2L(config-line)#logg s
B-SW-2L(config-line)#exit
2,二层交换上创建VLAN并配置TRUNK
B-SW-2L#vlan database
B-SW-2L(vlan)#vl 2
B-SW-2L(vlan)#vl 3
B-SW-2L(vlan)#exit
B-SW-2L#conf t
B-SW-2L(config)#int f0/2
B-SW-2L(config-if)#sw ac vl 2
B-SW-2L(config-if)#int f0/3
B-SW-2L(config-if)#sw ac vl 3
B-SW-2L(config)#int f0/14
B-SW-2L(config-if)#sw mo tr
B-SW-2L(config-if)#end
3,验证
B-SW-2L#show int f0/14 switchport
B-SW-2L#show vlan-switch bri
B-SW-2L#show run
 
A-SW-3L三层交换机配置:
1,模拟器开启后基本配置
Router#conf t
Router(config)#ho A-SW-3L
A-SW-3L(config)#no ip do lo
A-SW-3L(config)#lin c 0
A-SW-3L(config-line)#no exec-t
A-SW-3L(config-line)#logg s
A-SW-3L(config-line)#exit
2,三层交换上创建并配置TRUNK
A-SW-3L#vlan database
A-SW-3L(vlan)#vl 2
A-SW-3L(vlan)#vl 3
A-SW-3L(vlan)#exit
A-SW-3L(config)#int f0/14
A-SW-3L(config-if)#sw mo tr
3,三层交换上配置各VLAN的IP地址
A-SW-3L(config)#int vl 1
A-SW-3L(config-if)#ip add 192.168.1.1 255.255.255.0
A-SW-3L(config-if)#no shu
A-SW-3L(config-if)#int vl 2
A-SW-3L(config-if)#ip add 192.168.2.1 255.255.255.0
A-SW-3L(config-if)#no shu
A-SW-3L(config-if)#int vl 3
A-SW-3L(config-if)#ip add 192.168.3.1 255.255.255.0
A-SW-3L(config-if)#no shu
A-SW-3L(config-if)#end
此时就可配置VPC并检验各VLAN主机是否能通信
VPCS 1 >ip 192.168.1.2 192.168.1.1
VPCS 1 >2
VPCS 2 >ip 192.168.2.2 192.168.2.1
VPCS 2 >3
VPCS 3 >ip 192.168.3.2 192.168.3.1
完成相关PING测试后查看三层交换机上的FIB表及邻接关系表内容
A-SW-3L#show ip cef
A-SW-3L#show adjacency detail
由此可看出二层交换机与三层交换机之间的区别

4,配置三层交换的路由接口、开启路由功能并添加默认路由
A-SW-3L(config)#ip routing
A-SW-3L(config)#int f0/15
A-SW-3L(config-if)#no switchport
A-SW-3L(config-if)#ip add 10.1.1.1 255.255.255.252
A-SW-3L(config-if)#no shu
A-SW-3L(config-if)#exit
A-SW-3L(config)#ip route 0.0.0.0 0.0.0.0 10.1.1.2
A-SW-3L(config)#end
5,验证
A-SW-3L#show ip int bri
A-SW-3L#show vlan-switch brief
A-SW-3L#show ip route
A-SW-3L#show run
 
路由器配置:
1,模拟器开启后基本配置
Router#conf t
Router(config)#no ip do lo
Router(config)#lin c 0
Router(config-line)#no exec-t
Router(config-line)#logg s
Router(config-line)#exit
2,配置接口IP并添加路由条目
Router#conf t
Router(config)#int f0/0
Router(config-if)#ip add 10.1.1.2 255.255.255.252
Router(config-if)#no shu
Router(config-if)#exit
Router(config)#ip route 192.168.1.0 255.255.255.0 10.1.1.1
Router(config)#ip route 192.168.2.0 255.255.255.0 10.1.1.1
Router(config)#ip route 192.168.3.0 255.255.255.0 10.1.1.1
此时在路由器上可以PING通各VLAN内的主机
3,验证
Router#show ip route
Router#show ip int bri
Router#show run
 
 
三层交换DHCP中继配置(接上)
1,在路由器上启用DHCP服务功能并设置每个地址池被排除的IP地址
Router#conf t
Router(config)#service dhcp
Router(config)#ip dhcp excluded-address 192.168.1.1 192.168.1.10
Router(config)#ip dhcp excluded-address 192.168.2.1 192.168.2.10
Router(config)#ip dhcp excluded-address 192.168.3.1 192.168.3.10
2,针对三个VLAN创建三个DHCP地址池
Router(config)#ip dhcp pool vlan1
Router(dhcp-config)#network 192.168.1.0 /24
Router(dhcp-config)#default-router 192.168.1.1
Router(dhcp-config)#dns-server 202.103.24.68 202.103.0.117
Router(dhcp-config)#lease 7
Router(dhcp-config)#exit
Router(config)#ip dhcp pool vlan2
Router(dhcp-config)#network 192.168.2.0 /24
Router(dhcp-config)#default-router 192.168.2.1
Router(dhcp-config)#dns-server 202.103.24.68 202.103.0.117
Router(dhcp-config)#lease 7
Router(dhcp-config)#exit
Router(config)#ip dhcp pool vlan2
Router(dhcp-config)#network 192.168.3.0 /24
Router(dhcp-config)#default-router 192.168.3.1
Router(dhcp-config)#dns-server 202.103.24.68 202.103.0.117
Router(dhcp-config)#lease 7
Router(dhcp-config)#exit
3,在三层交换机上启用DHCP中继
A-SW-3L(config)#int vl 1
A-SW-3L(config-if)#ip helper-address 10.1.1.2 
A-SW-3L(config-if)#int vl 2
A-SW-3L(config-if)#ip helper-address 10.1.1.2
A-SW-3L(config-if)#int vl 3
A-SW-3L(config-if)#ip helper-address 10.1.1.2
4,VPC上进行DHCP动态IP地址测试
1>dhcp
2>dhcp
3>dhcp

DHCP服务器关指令:
service dhcp
#开启DHCP服务 
no ip dhcp conflict logging 
#不记录DHCP相关错误信息日志
ip dhcp excluded-address 192.168.1.1 192.168.1.10 
#不分配的IP地址段
ip dhcp pool benet
#创建名为benet的DHCP服务器地址池
network 192.168.1.0 /24
#分配的IP地址段
default-router 192.168.1.1 192.168.1.2
#分配的网关
dns-server 202.103.24.68 202.103.0.117
#分配的DNS服务器地址
netbios-name-server 192.168.1.10
#指定netbios服务器
lease 7
#IP地址租期7天
show ip dhcp pool
#查看服务器地址池信息
show ip dhcp binding
#查看已分配的IP地址绑定MAC信息
 
 
注:
模拟器用的3640,所以在模拟三层交换时默认路由功能已开启
VPC 1.5a以上版本才支持DHCP
1,如果DHCP服务器上不配置DHCP分配时排除的IP地址范围,客户端会获得哪个IP地址?
2,如果DHCP服务器位于二层交换机的VLAN1的接口范围内,只需要在三层交换机上配置哪几个VLAN的DHCP中继?