单臂路由实战讲解

单臂路由(router-on-a-stick)是指在路由器的一个接口上通过配置子接口(或“逻辑接口”,并不存在真正物理接口)的方式,实现原来相互隔离的不同VLAN(虚拟局域网)之间的互联互通。

实验步骤

新建 packer tracer 拓扑图

当交换机设置两个 Vlan 时,逻辑上已经成为两个网络,广播被隔离了。两个 Vlan 的网络要通信,必须通过路由器,如果接入路由器的一个物理端口,则必须有两个子接口分别与两个 Vlan 对应,同时还要求与路由器相连得交换机的端口 fa 0/1 要设置为 trunk,因为这个接口要通过两个 Vlan 的数据包。

检查设置情况,应该能够正确的看到 Vlan 和 Trunk 信息。

计算机的网关分别指向路由器的子接口。

配置子接口,开启路由器物理接口。

默认封装 dot1q 协议。

配置路由器子接口 IP 地址。

实验设备

PC 2 台;Router_2811 1 台;Switch_2960 1 台

PC1
IP: 192.168.1.2
Submask: 255.255.255.0
Gateway:192.168.1.1

PC2
IP: 192.168.2.2
Submask: 255.255.255.0
Gateway:192.168.2.1

Switch
en
conf t
vlan 2
exit
vlan 3
exit
interface fastEthernet 0/2
switchport access vlan 2
exit
int fa 0/3
switchport access vlan 3
exit
int fa 0/1
switchport mode trunk
end
show vlan


Router
en
conf t
int fa 0/0
no shutdown
exit
interface fast 0/0.1
encapsulation dot1q 2 #将以太网子接口0/0.1划分到vlan 2,并且封装格式为802.1q
ip address 192.168.1.1 255.255.255.0
exit

int fa 0/0.2
encapsulation dot1q 3 #将以太网子接口0/0.2划分到vlan 3,并且封装格式为802.1q
ip address 192.168.2.1 255.255.255.0
end
show ip route

实战演练

配置交换机

Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 2
Switch(config-vlan)#exit
Switch(config)#vlan 3
Switch(config-vlan)#exit
Switch(config)#int fa 0/2
Switch(config-if)#sw access vlan 2
Switch(config-if)#exit
Switch(config)#int fa 0/3
Switch(config-if)#sw access vlan 3
Switch(config-if)#exit
Switch(config)#int fa 0/1
Switch(config-if)#sw mode trunk
Switch(config-if)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console

Switch#show vlan

VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/1, Fa0/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
2 VLAN0002 active Fa0/2
3 VLAN0003 active Fa0/3
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup

VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1 enet 100001 1500 - - - - - 0 0
2 enet 100002 1500 - - - - - 0 0
3 enet 100003 1500 - - - - - 0 0
1002 fddi 101002 1500 - - - - - 0 0
--More--

配置路由器

--- System Configuration Dialog ---

Continue with configuration dialog? [yes/no]: no


Press RETURN to get started!



Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int fa 0/0
Router(config-if)#no shutdown

%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

Router(config-if)#exit
Router(config)#int fa 0/0.1

%LINK-5-CHANGED: Interface FastEthernet0/0.1, changed state to up
Router(config-subif)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.1, changed state to up

Router(config-subif)#encapsulation dot1q 2 #将以太网子接口0/0.1划分到vlan 2,并且封装格式为802.1q
Router(config-subif)#ip address 192.168.1.1 255.255.255.0
Router(config-subif)#exit
Router(config)#int fa 0/0.2

%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
Router(config-subif)#encapsulation dot1q 3 #将以太网子接口0/0.2划分到vlan 3,并且封装格式为802.1q
Router(config-subif)#ip address 192.168.2.1 255.255.255.0
Router(config-subif)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console

Router#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

C 192.168.1.0/24 is directly connected, FastEthernet0/0.1
C 192.168.2.0/24 is directly connected, FastEthernet0/0.2
Router#

测试

PC1 ping PC2

PC>ipconfig

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=20ms TTL=127
Reply from 192.168.2.2: bytes=32 time=22ms TTL=127
Reply from 192.168.2.2: bytes=32 time=23ms 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 = 20ms, Maximum = 23ms, Average = 21ms

PC>ping 192.168.2.2

Pinging 192.168.2.2 with 32 bytes of data:

Reply from 192.168.2.2: bytes=32 time=28ms TTL=127
Reply from 192.168.2.2: bytes=32 time=19ms TTL=127
Reply from 192.168.2.2: bytes=32 time=21ms TTL=127
Reply from 192.168.2.2: bytes=32 time=22ms TTL=127

Ping statistics for 192.168.2.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 19ms, Maximum = 28ms, Average = 22ms

PC2 ping PC1

PC>ipconfig

IP Address......................: 192.168.2.2
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.2.1

PC>ping 192.168.1.2

Pinging 192.168.1.2 with 32 bytes of data:

Reply from 192.168.1.2: bytes=32 time=22ms TTL=127
Reply from 192.168.1.2: bytes=32 time=26ms TTL=127
Reply from 192.168.1.2: bytes=32 time=24ms TTL=127
Reply from 192.168.1.2: bytes=32 time=21ms TTL=127

Ping statistics for 192.168.1.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 21ms, Maximum = 26ms, Average = 23ms

文章来源网络,作者:管理,如若转载,请注明出处:https://shuyeidc.com/wp/200252.html<

(0)
管理的头像管理
上一篇2025-04-05 05:18
下一篇 2025-04-05 05:19

相关推荐

  • 服务器被植入木马怎么彻底清除,彻底清除木马的方法有哪些?

    服务器被植入木马后,彻底清除的唯一路径是:立即断网隔离,备份关键数据,使用专业工具全盘扫描并手动排查残留,随后重装操作系统或从干净备份恢复,全面修补漏洞与加固配置,最后持续监控至少两周,确认感染并执行隔离木马最怕被断网,第一步就是切断它与外界的联系,如果发现服务器响应慢、流量异常、CPU跑满,或者收到安全告警……

    2026-07-27
    0
  • 网站并发量高服务器扛不住怎么办,如何解决

    首段核心答案当网站并发量激增导致服务器响应缓慢甚至宕机时,根本解决路径是实施弹性扩容、流量分发、性能优化和纵深防御四位一体的策略,具体操作需结合监控诊断、架构调整和专业化服务商支持,诊断并发瓶颈:定位问题根源如何判断服务器是否到达极限在动手优化之前,先搞清楚“扛不住”的具体表现,常见指标包括CPU使用率持续超过……

    2026-07-27
    0
  • 如何拦截ByteSpider爬虫不影响收录,有哪些技巧?

    正确配置robots.txt和服务器User-Agent识别,即可精准拦截ByteSpider爬虫,同时确保百度爬虫正常抓取,不影响收录,理解ByteSpider爬虫:它是什么,为何要拦截ByteSpider是字节跳动旗下的网页爬虫,主要用于采集网页内容,服务于头条搜索、抖音搜索等产品,大多数情况下,我们欢迎爬……

    2026-07-27
    0
  • 服务器流量异常时怎么排查是不是被攻击,是什么原因?

    当服务器流量异常时,首先通过带宽监控、连接数分析和异常流量特征判断是否被攻击,然后采取相应处置措施,识别流量异常的常见信号你可能会遇到这种情况:某天服务器突然响应变慢,或者网站打不开,甚至远程连接都被中断,流量异常通常会在几个方面暴露出来,早期发现能减少损失,带宽占用飙升使用 sar -n DEV 1 5 或……

    2026-07-27
    0
  • 国内访问美国服务器太慢怎么办,为什么访问速度慢

    优化国内访问美国服务器速度,核心在于组合使用CDN边缘节点缓存、优质国际线路(如CN2 GIA)和TCP协议层优化,同时选择具备持牌自营机房和跨境网络资质的专业服务商,为什么国内访问美国服务器延迟居高不下物理距离是首要因素,中美海底光缆总长约1.3万公里,信号往返至少需要120毫秒,但实际延迟往往超过200毫秒……

    2026-07-27
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注