路由器单臂路由配置------配置子接口是配置单臂路由的关键
拓扑图如下:
文章图片
配置交换机S1
Switch>en
Switch#conf t
Enter configuration commands, one per line.End with CNTL/Z.
Switch(config)#host S1
S1(config)#vlan 20
S1(config-vlan)#vlan 30
S1(config-vlan)#exit
S1(config)#int fa0/2
S1(config-if)#switchport mode access
S1(config-if)#switchport access vlan 20
S1(config-if)#exit
S1(config)#int fa0/3
S1(config-if)#switchport mode access
S1(config-if)#switchport access vlan 30
S1(config-if)#exit
S1(config)#int fa0/1
S1(config-if)#switchport mode access
S1(config-if)#switchport mode trunk
S1(config-if)#switchport trunk allowed vlan all!--- Trunk端口允许所有VLAN的发送和接口传输,这也是默认状态,该条指令可选。
S1(config-if)#end
S1#show vlan
VLAN NameStatusPorts
---- -------------------------------- --------- -------------------------------
1defaultactiveFa0/4, Fa0/5, Fa0/6, Fa0/7
Fa0/8, Fa0/9, Fa0/10, Fa0/11
Fa0/12, Fa0/13, Fa0/14, Fa0/15
Fa0/16, Fa0/17, Fa0/18, Fa0/19
Fa0/20, Fa0/21, Fa0/22, Fa0/23
Fa0/24, Gig1/1, Gig1/2
20VLAN0020activeFa0/2
30VLAN0030activeFa0/3
1002 fddi-defaultact/unsup
1003 token-ring-defaultact/unsup
1004 fddinet-defaultact/unsup
1005 trnet-defaultact/unsup
VLAN TypeSAIDMTUParent RingNo BridgeNo StpBrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1enet1000011500-----00
20enet1000201500-----00
30enet1000301500-----00
1002 fddi1010021500-----00
1003 tr1010031500-----00
1004 fdnet 1010041500---ieee -00
1005 trnet 1010051500---ibm-00
Remote SPAN VLANs
------------------------------------------------------------------------------
Primary Secondary TypePorts
------- --------- ----------------- ------------------------------------------
S1#
配置路由器R1
Router>en
Router#conf t
Enter configuration commands, one per line.End with CNTL/Z.
Router(config)#host R1
R1(config)#int fa0/0
R1(config-if)#no shut
R1(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R1(config-if)#exit
R1(config)#int fa0/0.1!--- 配置子接口是配置单臂路由的关键,它是一个逻辑接口,实际并不存在的物理接口,其功能却和物理接口一样。
R1(config-subif)#
%LINK-5-CHANGED: Interface FastEthernet0/0.1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.1, changed state to up
R1(config-subif)#encapsulation dot1q 20!--- 配置子接口使用的802.1Q协议,最后面的20是VLAN号
R1(config-subif)#ip add 192.168.1.1 255.255.255.0
R1(config-subif)#exit
R1(config)#int fa0/0.2
R1(config-subif)#
%LINK-5-CHANGED: Interface FastEthernet0/0.2, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.2, changed state to up
R1(config-subif)#encapsulation dot1q 30
R1(config-subif)#ip add 192.168.2.1 255.255.255.0
R1(config-subif)#end
R1#
%SYS-5-CONFIG_I: Configured from console by console
R1#show ip route
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - IS-IS, 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
C192.168.1.0/24 is directly connected, FastEthernet0/0.1
C192.168.2.0/24 is directly connected, FastEthernet0/0.2
R1#
测试单臂路由配置:
PC>ipconfig
FastEthernet0 Connection:(default port)
Link-local IPv6 Address.........: FE80::202:4AFF:FE14:89CB
IP Address......................: 192.168.1.2
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.1.1
PC>ping 192.168.2.2
Pinging 192.168.2.2 with 32 bytes of data:
Request timed out.
Reply from 192.168.2.2: bytes=32 time=0ms TTL=127
Reply from 192.168.2.2: bytes=32 time=0ms TTL=127
Reply from 192.168.2.2: bytes=32 time=0ms TTL=127
Ping statistics for 192.168.2.2:
Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
PC>
测试结构表明配置完全正确
【路由器单臂路由配置------配置子接口是配置单臂路由的关键】
推荐阅读
- day|day 28 设置路由表
- 思科路由映射表控制BGP路径的方法和实例
- 微信小程序路由跳转
- 测试环境与路由|测试环境与路由 | 阿里巴巴DevOps实践指南
- 爪哇学习笔记——从pushState方法看前端路由
- nuxt 路由拦截
- 伊朗Cisco路由器遭黑客攻击|伊朗Cisco路由器遭黑客攻击 全国互联网几乎瘫痪
- Adnroid|一个方法搞定安卓路由跳转
- angular--路由之子路由
- Linux内核机制|路由分类