Login

Navigation

This articles is published 952 days ago and last updated 949 days ago, some information may be out of date.

Inter-VLAN Routing (Router on a Stick)

Single arm routing_Cover.png

前言:
所有的練習是基於「Cisco Packet Tracer」軟件平台。
原理:
Inter-VLAN Routing 意思是使原本相互隔離的vlan間互通,而Router on a Stick(也叫單臂路由) 是指在路由器的單口上實現vlan互通。
目標:
在路由器的單網口上配置多組vlan,在不同的vlan間相互通信。
模擬場景:

Diagram_2021-09-18_095748.png

vLanIP(Subnet)
vlan1010.10.10.0/24
vlan2010.10.20.0/24
PC1在vlan10,PC2在vlan20,两部電腦的IP在不同的網段,透過路由器的設定使PC1和PC2可以相互溝通。
路由器的設置(Cisco 2901)

Router_2021-09-18_092543.png

Router>enable
Router#configure terminal
進入Global Configuration Mode模式
Router(config)#interface gigabitEthernet 0/1
Router(config-if)#no shutdown
Router(config-if)#exit
選物理取網口0/1,并啟用
Router(config)#interface gigabitEthernet 0/1.10
Router(config-subif)#encapsulation dot1Q 10
Router(config-subif)#ip address 10.10.10.1 255.255.255.0
Router(config-subif)#exit
在物理網口0/1上配置子網口

配置802.1Q協定,并劃分vlan10

設定網口IP地址

Router(config)#interface gigabitEthernet 0/1.20
Router(config-subif)#encapsulation dot1Q 20
Router(config-subif)#ip address 10.10.20.1 255.255.255.0
Router(config-subif)#end
在物理網口0/1上配置子網口

配置802.1Q協定,并劃分vlan20

設定網口IP地址

Router#write memory
存檔
路由器的DHCP伺服器設置

Router_DHCP_2021-09-18_094946.png

Router>enable
Router#configure terminal
進入Global Configuration Mode模式
Router(config)#ip dhcp excluded-address 10.10.10.1 10.10.10.50
Router(config)#ip dhcp pool dhcp.vlan10
Router(dhcp-config)#default-router 10.10.10.1
Router(dhcp-config)#network 10.10.10.0 255.255.255.0
Router(dhcp-config)#dns-server 1.1.1.1
Router(dhcp-config)#exit
10.10.10.1 - 10.10.10.50為保留IP地址段,不分派到裝置。

建立地址分派池名稱為dhcp.vlan10

預設路由IP地址 10.10.10.1

網段是 10.10.10.0/24

DNS伺服器為 1.1.1.1

Router(config)#ip dhcp excluded-address 10.10.20.1 10.10.20.50
Router(config)#ip dhcp pool dhcp.vlan20
Router(dhcp-config)#default-router 10.10.20.1
Router(dhcp-config)#network 10.10.20.0 255.255.255.0
Router(dhcp-config)#dns-server 1.1.1.1
Router(dhcp-config)#exit
10.10.20.1 - 10.10.20.50為保留IP地址段,不分派到裝置。

建立地址分派池名稱為dhcp.vlan20

預設路由IP地址 10.10.20.1

網段是 10.10.20.0/24

DNS伺服器為 1.1.1.1

Router(dhcp-config)#end
Router#write
存檔
交換機的設置(Cisco 2960-24T)

Switch_2021-09-18_091732.png

Switch>enable
Switch#configure terminal
進入Global Configuration Mode模式
Switch(config)#vlan 10
Switch(config-vlan)#exit
建立vlan10
Switch(config)#vlan 20
Switch(config-vlan)#exit
建立vlan20
Switch(config)#interface range fastEthernet 0/1-4
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#switchport access vlan 10
Switch(config-if-range)#exit
劃分網口0/1-4給Vlan10
Switch(config)#interface range fastEthernet 0/5-8
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#switchport access vlan 20
Switch(config-if-range)#exit
劃分網口0/5-8給Vlan20
Switch(config)#interface gigabitEthernet 0/1
Switch(config-if)#switchport mode trunk
Switch(config-if)#end
設置連接路由器網口 g0/1為Trunk模式 (*所有vlan數據經這接口傳送到路由器)
Switch#copy running-config startup-config
存檔
電腦互通測試

2021-09-18_095342.png

PC1分配到的IP地址為10.10.10.51 (vlan10網段)

2021-09-18_095352.png

PC1分配到的IP地址為10.10.20.51 (vlan20網段)

2021-09-18_095534.png

PC1 Ping PC2 (可通信)

2021-09-18_095519.png

PC2 Ping PC1 (可通信)