独臂路由实现不同vlan之间的通信

所谓独臂路由,我的理解是这样的,采用路由器其中一个物理接口通过划分子接口(也就是虚拟的接口)来实现不同vlan间的路由,这样做有个好处,此物理接口的一侧的交换机可以容许划分多个不同的vlan,并且做够做到相互通信,同时也节约了物理接口。
 
实验拓扑图:
 
实验描述:
pc0和pc1分属于vlan2和vlan3,它们通过路由器独臂路由实现通信。
pc0
 ip  192.168.1.2
 mask  255.255.255.0
 gataway  192.168.1.1
pc1
 ip  192.168.2.2
 mask  255.255.255.0
 gataway  192.168.2.1
 
 
实验命令:
对于二层交换机
Switch>enable(进入特权模式,下一行以#号提示)
Switch#configure terminal(进入配置模式)
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#exit
%SYS-5-CONFIG_I: Configured from console by console
Switch#vlan database(进入vlan配置模式)
% Warning: It is recommended to configure VLAN from config mode,
  as VLAN database mode is being deprecated. Please consult user
  documentation for configuring VTP/VLAN in config mode.
Switch(vlan)#vlan 2 name 2(创立vlan2 命名2)
VLAN 2 added:
    Name: 2
Switch(vlan)#vlan 3 name 3
VLAN 3 added:
    Name: 3
Switch(vlan)#exit
APPLY completed.
Exiting....
Switch#conf
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#int f0/1(进入端口配置模式)
Switch(config-if)#switchport mode access(划分接口为vlan接口模式)
Switch(config-if)#switchport access vlan 2(将端口f0/1划分到vlan 2)
Switch(config-if)#int f0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 3
Switch(config-if)#int f0/3
Switch(config-if)#switchport mode trunk(将端口f0/3划分为trunk(中继)模式)
注:端口在此模式下可以外接多个不同的vlan,也就是说此端口可以承载多个不同的vlan信息
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to up
Switch(config-if)#exit
Switch(config)#exit
%SYS-5-CONFIG_I: Configured from console by console
Switch#copy running-config startup-config(保存,这是必须要做的,否则配置会丢失)
Destination filename [startup-config]?
Building configuration...
[OK]
 
对于路由器
 
 
 
 
Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#int f0/0
Router(config-if)#no shutdown(开启端口)
Router(config-if)#int f0/0.1(进入子接口配置模式,也就是逻辑接口)
Router(config-subif)#ip add 192.168.1.1 255.255.255.0(设置子接口ip地址)
Router(config-subif)#en
Router(config-subif)#encapsulation dot1q 2(子接口封装采用802.1q协议,后面的2也就是vlan2)
Router(config-subif)#int f0/0.2
Router(config-subif)#ip add 192.168.2.1 255.255.255.0
Router(config-subif)#encapsulation dot1q 3
Router(config-subif)#end
%SYS-5-CONFIG_I: Configured from console by console
Router#copy running-config startup-config
Destination filename [startup-config]?
Building configuration...
[OK]
 
 
测试
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=125ms TTL=127
Reply from 192.168.2.2: bytes=32 time=111ms TTL=127
Reply from 192.168.2.2: bytes=32 time=93ms 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 = 93ms, Maximum = 125ms, Average = 109ms
总结
对于路由器,默认情况是端口都是关闭的,我们需要在端口配置的模式下敲no shutdown这时开启端口,别忘了即使我们在路由器物理端口没做任何的配置命令,但是必须首先保证它是开启的,这样才能接着配置相应的子接口。
 

你可能感兴趣的:(网络,职场,路由,休闲)