今天和大家分享一个技术问题,是我们在IDC运维和网络管理中经常操作的内容,让不同VLAN间相互通信。
只要讨论的是:单臂路由(如下图)
创建VLAN
Switch(config)#vlan 10
Switch(config-vlan)#vlan 20
进入接口配置模式分别把对应的接口,加入对应的vlan:
Switch(config)#interface fastEthernet 0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 10
Switch(config-if)#interface fastEthernet 0/3
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
把0/2变成trunk口(默认是access口)
Switch(config-if)#switchport mode trunk
交换机配置好了
路由器的配置:
Router>
Router>enable
Router#configure terminal
Router(config)#inter fas 0/0
Router(config-if)#no shutdown
注意:单臂路由的配置父接口一定要no shutdown
Router(config-if)#exit
Router(config)#int fas 0/0.10
Router(config-subif)#encapsulation dot1Q 10
注意:在配置ip时一定要先封装802.1q协议
Router(config-subif)#ip address 192.168.10.1 255.255.255.0
Router(config-subif)#no shutdown
Router(config-subif)#int fas 0/0.20
Router(config-subif)#ip address 192.168.20.1 255.255.255.0
Router(config-subif)#encapsulation dot1Q 20
Router(config-subif)#ip address 192.168.20.1 255.255.255.0
Router(config-subif)#no shutdown
查看路由表:
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.10.0/24 is directly connected, FastEthernet0/0.10
C 192.168.20.0/24 is directly connected, FastEthernet0/0.20
在PC
ip 192.168.10.100
netmask 255.255.255.0
gateway 192.168.10.1
注意:网关一定得是路由器对应子接口的IP,不然会ping不通
使用三层交换机 svi
交换机配置:
Switch(config)#vlan 10
Switch(config-vlan)#vlan 20
Switch(config-vlan)#exi
Switch(config)#int vlan 10
Switch(config-if)#ip add 192.168.10.1 255.255.255.0
Switch(config-if)#no shutdown
Switch(config)#int vlan 20
Switch(config-if)#ip add 192.168.20.1 255.255.255.0
Switch(config-if)#no shutdown
Switch(config)#interface fastEthernet 0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 10
Switch(config-if)#interface fastEthernet 0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
Switch#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.10.0/24 is directly connected, Vlan10
C 192.168.20.0/24 is directly connected, Vlan
PC的配置和单臂路由一样
1,三层交换机有的需要手动开启路由功能IP routing
2,也可以在二层交换机上连三层交换机做单臂路由
如果你是IT技术,想了解VLAN,可以一起做技术沟通。