拓扑
配置
pc1
lsw1
[Huawei]sys LSW1
[LSW1]vlan batch 10 20
[LSW1]inte gi 0/0/2
[LSW1-GigabitEthernet0/0/2]port link-type access
[LSW1-GigabitEthernet0/0/2]port default vlan 10
[LSW1-GigabitEthernet0/0/2]inte gi 0/0/1
[LSW1-GigabitEthernet0/0/1]port link-type access
[LSW1-GigabitEthernet0/0/1]port default vlan 20
[LSW1-GigabitEthernet0/0/1]inte vlan 10
[LSW1-Vlanif10]ip addr 192.168.1.254 255.255.255.0
[LSW1-Vlanif10]inte vlan 20
[LSW1-Vlanif20]ip address 11.1.1.1 255.255.255.0
[LSW1-Vlanif20]q
[LSW1]ospf 1 router-id 2.2.2.2
[LSW1-ospf-1]area 0
[LSW1-ospf-1-area-0.0.0.0]network 11.1.1.1 0.0.0.0
[LSW1-ospf-1-area-0.0.0.0]network 192.168.1.254 0.0.0.0
AR1
[Huawei]sys AR1
[AR1]inte gi 0/0/1
[AR1-GigabitEthernet0/0/1]ip addr 11.1.1.2 255.255.255.0
[AR1-GigabitEthernet0/0/1]inte gi 0/0/0
[AR1-GigabitEthernet0/0/0]ip addr 12.1.1.1 255.255.255.0
[AR1-GigabitEthernet0/0/0]inte lo 1
[AR1-LoopBack1]ip address 1.1.1.1 255.255.255.255
[AR1-LoopBack1]q
[AR1]ospf 1 router-id 1.1.1.1
[AR1-ospf-1]default-route-advertise //下发默认路由,可选添加参数always,不添加always的时候只有当本设备有默认路由下会下发,没有则不发,加上always参数意思为不管本设备有无缺省路由都下发
[AR1-ospf-1]area 0
[AR1-ospf-1-area-0.0.0.0]network 11.1.1.2 0.0.0.0
[AR1-ospf-1-area-0.0.0.0]network 1.1.1.1 0.0.0.0
[AR1-ospf-1]q
[AR1]ip route-static 0.0.0.0 0 12.1.1.2
AR2
<Huawei>sys
[Huawei]sys AR2
[AR2]inte lo 1
[AR2-LoopBack1]ip addr 8.8.8.8 255.255.255.255
[AR2-LoopBack1]inte gi 0/0/0
[AR2-GigabitEthernet0/0/0]ip addr 12.1.1.2 255.255.255.0
[AR2]ip route-static 192.168.1.0 255.255.255.0 12.1.1.1 //现网中没有此步,运营商个内网回复使用的是nat技术,为了实验的完整性配置静态回程路由
通讯验证
[LSW1]dis ip routing-table
Route Flags: R - relay, D - download to fib
\------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 8 Routes : 8
Destination/Mask Proto Pre Cost Flags NextHop Interface
0.0.0.0/0 O_ASE 150 1 D 11.1.1.2 Vlanif20 //由AR1下发的默认路由
1.1.1.1/32 OSPF 10 1 D 11.1.1.2 Vlanif20
11.1.1.0/24 Direct 0 0 D 11.1.1.1 Vlanif20
11.1.1.1/32 Direct 0 0 D 127.0.0.1 Vlanif20
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.1.0/24 Direct 0 0 D 192.168.1.254 Vlanif10
192.168.1.254/32 Direct 0 0 D 127.0.0.1 Vlanif10