【network实践】单臂路由的实现

vlan間ルーティング(ROUTER ON A STICK,单臂路由)在很多博客上都有记录,物理上的要实现两个不同网段的互联的拓扑图如下


但是现在只需要一台路由器和一台switch通过access和trunk制造虚拟的网口就可实现两个不同网段在同一台switch上的互联。

演习


条件:

  • 拓扑图如上所示
  • 建立单臂路由实现三个PC之间的相互通信

Router设定

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Router(config)#interface fastethernet 0.1
Router(config-subif)#encapsulation dot1q 1
Router(config-subif)#ip address 172.16.1.254 255.255.255.0
Router(config-subif)#exit
Router(config)#interface fastethernet 0.10
Router(config-subif)#encapsulation dot1q 10
Router(config-subif)#ip address 172.16.10.254 255.255.255.0
Router(config-subif)#exit
Router(config)#interface fastethernet 0.20
Router(config-subif)#encapsulation dot1q 20
Router(config-subif)#ip address 172.16.20.254 255.255.255.0
Router(config-subif)#exit
Router(config)#interface fastethernet 0.99
Router(config-subif)#encapsulation dot1q 99 native
Router(config-subif)#exit
Router(config)#interface fastethernet 0
Router(config-if)#no shutdown

switch设定

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Switch(config)#vlan 10,20,99
Switch(config-vlan)#exit
Switch(config)#interface range fastethernet 0/1 - 3
switch(config-if-range)#switchport mode access
Switch(config-if-range)#interface fastethernet 0/2
Switch(config-if)#switchport access vlan 10
Switch(config-if)#interface fastethernet 0/3
Switch(config-if)#switchport access vlan 20
Switch(config-if)#interface fastethernet 0/12
Switch(config-if)#switchport trunk encapsulation dot1q
Switch(config-if)#switchport mode trunk
//Switch(config-if)#switchport nonegotiate 2950switch已经不需要这一步骤
Switch(config-if)#switchport trunk native vlan 99
Switch(config-if)#interface vlan 1
Switch(config-if)#ip address 172.16.1.100 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#ip default-gateway 172.16.1.254
Switch(config)#exit

单臂路由的验证

Router

1
2
3
Router#show ip interface [brief]
Router#show ip route
Router#show vlans

Switch

1
2
3
4
5
Switch#show interfaces trunk
Switch#show interfaces switchport
Switch#show vlan [brief]
Switch#show interfaces vlan <vlan-id>
Switch#show run

演习结果

switch端结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Switch#show vlan

VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/17, Fa0/18, Fa0/19, Fa0/20
Fa0/21, Fa0/22, Fa0/23
10 VLAN0010 active Fa0/1, Fa0/2, Fa0/4, Fa0/5
Fa0/6, Fa0/7, Fa0/8
20 VLAN0020 active Fa0/3, Fa0/9, Fa0/10, Fa0/11
Fa0/12, Fa0/13, Fa0/14, Fa0/15
Fa0/16
99 VLAN0099 active
1002 fddi-default active
1003 token-ring-default active
1004 fddinet-default active
1005 trnet-default active

VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1 enet 100001 1500 - - - - - 0 0
10 enet 100010 1500 - - - - - 0 0
20 enet 100020 1500 - - - - - 0 0
99 enet 100099 1500 - - - - - 0 0
1002 fddi 101002 1500 - - - - - 0 0
1003 tr 101003 1500 - - - - - 0 0
1004 fdnet 101004 1500 - - - ieee - 0 0
1005 trnet 101005 1500 - - - ibm - 0 0

Remote SPAN VLANs
------------------------------------------------------------------------------


Primary Secondary Type Ports
------- --------- ----------------- ------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
Switch#show interface trunk

Port Mode Encapsulation Status Native vlan
Fa0/24 on 802.1q trunking 1

Port Vlans allowed on trunk
Fa0/24 1-4094

Port Vlans allowed and active in management domain
Fa0/24 1,10,20,99

Port Vlans in spanning tree forwarding state and not pruned
Fa0/24 1,10,20,99

Router端结果

1
2
3
4
5
6
7
8
9
10
11
12
13
Router#show ip interface brief
Interface IP-Address OK? Method Status Prot ocol
FastEthernet0 unassigned YES NVRAM up up
FastEthernet0.1 172.16.1.254 YES manual up up
FastEthernet0.10 172.16.10.254 YES manual up up
FastEthernet0.20 172.16.20.254 YES manual up up
FastEthernet0.99 unassigned YES unset up up
FastEthernet1 unassigned YES NVRAM up down
BRI0 unassigned YES NVRAM administratively down down
BRI0:1 unassigned YES unset administratively down down
BRI0:2 unassigned YES unset administratively down down
FastEthernet2 unassigned YES unset up down
FastEthernet3 unassigned YES unset up down
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Router#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route

Gateway of last resort is not set

172.16.0.0/24 is subnetted, 3 subnets
C 172.16.20.0 is directly connected, FastEthernet0.20
C 172.16.10.0 is directly connected, FastEthernet0.10
C 172.16.1.0 is directly connected, FastEthernet0.1

感想

做完这个实验才理解了为什么单臂路由为什么在network里如此重要,也理解了为什么前两节课先生要那么大力气讲access和trunk的作用,通过路由器的虚拟网口,可以变相地将一台路由器当作多台使用(毕竟路由器那么贵),switch也变相承担了路由器的部分功能(switch相对便宜),但是虚拟网口是否能无限扩容并且实际体验是否能跟物理接续体验一致也是以后值得研究的课题。


【network实践】单臂路由的实现
http://liuminxuan.github.io/2018/12/05/network实践笔记:单臂路由的实现/
发布于
2018年12月5日
许可协议