
實驗:如上圖
公司 劃分了4個區域網路、分别是1.0、 2.0、 3.0、 4.0網段,分别接到2個交換機,再連上路由器後上網,現需要4個網段能夠互通。
首先把PC機IP 按圖配好。然後配置SW2交換機,指令如下:
SW2>
enable
configure terminal
enable secret 163.com(設定密文密碼163.com)
line vyt 0 4 設定虛拟端口0-4 用于遠端telnet
password 163.com
login 設定生效
line console 0 配置接口
password 163.com
login
exit
vlan 10建立Vlan10
interface vlan 10進入vlan 10
ip address 192.168.1.100 255.255.255.0 配置IP
no shutdown 啟用
vlan 20
interface vlan 20
ip address 192.168.2.100 255.255.255.0
no shutdown
interface fa0/1
switchport mode access 設定fa0/1端口為 access 模式
switchport access vlan 10把端口加入vlan 10
spanning-tree portfast 設定成快速端口
interface fa0/2
switchport mode access
switchport access vlan 20
spanning-tree portfast
interface range fa 0/11,fa 0/13,fa 0/16 - fa 0/20
switchport access vlan 10 把fa 0/11 13 16 17 18 19 20 端口加入Vlan10
interface fa 0/10
switchport trunk encapsulation dot1q 把端口封裝成dot1q協定
switchport mode trunk 把 10端口設成trunk 模式,就是可以跑多個vlan
switchport trunk allowed vlan all (允許所有vlan通過此端口,可寫可不寫,一般情況下trunk本來就預設所有vlan通過)
no shutdown
interface fa 0/5
switchport mode trunk
switchport trunk encapsulation
no shutdown
到這裡SW2交換機配置完畢,檢視一下有沒有配置錯誤:檢視結果和上面配置無誤
show vlan查 vlan
show ip interface brief查IP和端口狀态
show ip running-config 檢視所有配置
右邊交換機SW3配置方法一樣。
現在用PC 測試一下網絡連通性、發現相同網段、相同vlan的可以互通,而不同網段不同vlan的不能通。
我再在SW2 交換機上加2台PC ,PC5 加入vlan 30 IP 192.168.3.2 ,PC6 加入vlan10 IP 192.168.3.3
再測試互通性,得出相同網段、相同vlan的可以互通,相同網段不同vlan也是不能互通的。
現在要在路由器R1上配置網關、使全網互通。
enable
configure terminal
interface fa 0/0
no shutdown
interface fa 0/0.10 建立.10子接口并進入
encapsulation dot1q 10 封裝端口為dot1q 标記為10(這裡要注意,标記号一定要和vlan号一緻,不然有時候會導緻網絡不通)
ip address 192.168.1.254 255.255.255.0配置網關IP
no shutdown
interface fa0/0.20
encapsulation dot1q 20
ip address 192.168.2.254 255.255.255.0
no shutdown
interface fa 0/0.30
encapsulation dot1q 30
ip address 192.168.3.254 255.255.255.0
no shutdown
interface fa 0/0.40
encapsulation dot1q 40
ip address 192.168.4.254 255.255.255.0
no shutdown
end
檢視一下配置情況,看看是否正确。
show ip interface brief
現在整個網絡配置全部完成,測試一下整個網絡的聯通性。
發現整個網絡通不了,原來是交換機SW2 的fa 0/10連路由器的端口沒有設定為trunk 模式,确記,要跑多個vlan 的端口接口處,一定要改成trunk 模式。
再測試後,發現192.168.3.3 與其它的不通,因為在同一個網絡裡有一個192.168.3網段在VLAN 30 裡,而3.3在VLAN 10裡,是以不通. 其它的網絡全是通的。