华为路由交换——三层交换机与路由器之间链路实现交互
交换机与路由器之间的链路连接的方法:
方法一:设置vlanif 和 静态路由
方法二:在交换机和路由器上运行ospf
拓扑图如下:
方法一配置命令:
sw1
interface GigabitEthernet0/0/1
port link-type access
port default vlan 10
#
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 10 20
#
interface GigabitEthernet0/0/3
port link-type access
port default vlan 20
sw2(需要注意的是在该交换机上要创建三个VLAN,还有相应的vlanif,并且vlanif的ip要设置成 终端的网关 ;交换机和路由器之间的链路状态是access)
vlan batch 10 20 99
interface Vlanif10
ip address 192.168.10.254 255.255.255.0
#
interface Vlanif20
ip address 192.168.20.254 255.255.255.0
#
interface Vlanif99
ip address 192.168.99.1 255.255.255.0
#
interface GigabitEthernet0/0/1
port link-type access
port default vlan 99
#
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 2 to 4094
#
ip route-static 0.0.0.0 0.0.0.0 192.168.99.2(设置静态 0.0.0.0 不管任何路由都吓一跳到99.2的端口)
R1
#
interface GigabitEthernet0/0/0
ip address 192.168.99.2 255.255.255.0
#
interface LoopBack1
ip address 192.168.100.1 255.255.255.0
#
ip route-static 192.168.10.0 255.255.255.0 192.168.99.1(设置静态目的网段路由10.0 或 20.0 都吓一跳到99.1)
ip route-static 192.168.20.0 255.255.255.0 192.168.99.1
最后进行ping测试
方法二:
sw1
interface GigabitEthernet0/0/1
port link-type access
port default vlan 10
#
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 10 20
#
interface GigabitEthernet0/0/3
port link-type access
port default vlan 20
sw2(在方法一的基础上;不静默vlanif99的原因是要让vlanif99当作G0/0/1端口发出相应的报文)
undo ip route-static 0.0.0.0 0.0.0.0 192.168.99.2
#
ospf 1 router-id 1.1.1.1
silent-interface Vlanif10
silent-interface Vlanif20
area 0.0.0.0
network 192.168.10.0 0.0.0.255
network 192.168.20.0 0.0.0.255
network 192.168.99.0 0.0.0.255
R1(在方法一的基础上)
undo ip route-static 192.168.10.0 255.255.255.0 192.168.99.1
undo ip route-static 192.168.20.0 255.255.255.0 192.168.99.1
#
area 0.0.0.0
network 192.168.99.0 0.0.0.255
network 192.168.100.0 0.0.0.255
(注意ospf必须是要在同一个进程下面,同一个area)