如何通过另一台交换机将交换机与路由器连接?

网络工程 思科 转变 VLAN 数据包追踪器
2021-07-10 08:59:49

在此处输入图片说明

路由器配置

Router#sh run
Building configuration...

Current configuration : 769 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router
!
!
!
!
!
!
!
!
ip cef
no ipv6 cef
!
!
!
!
!
!
!
!
!
!
!
!
spanning-tree mode pvst
!
!
!
!
!
!
interface FastEthernet0/0
 description connecting to switch0
 no ip address
 duplex auto
 speed auto
!
interface FastEthernet0/0.10
 encapsulation dot1Q 10
 ip address 192.168.10.2 255.255.255.224
!
interface FastEthernet0/0.20
 encapsulation dot1Q 20
 ip address 192.168.10.34 255.255.255.224
!
interface FastEthernet0/1
 no ip address
 duplex auto
 speed auto
 shutdown
!
interface Vlan1
 no ip address
 shutdown
!
ip classless
!
ip flow-export version 9
!
!
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
 login
!
!
!
end

交换机0配置

Switch#sh run
Building configuration...

Current configuration : 1293 bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Switch
!
!
!
!
!
spanning-tree mode pvst
spanning-tree extend system-id
!
interface FastEthernet0/1
 description connecting to router
 switchport mode trunk
!
interface FastEthernet0/2
 description connecting to switch1
 switchport mode trunk
!
interface FastEthernet0/3
 description connecting to a pc which is in vlan10
 switchport access vlan 10
 switchport mode access
!
interface FastEthernet0/4
!
interface FastEthernet0/5
!
interface FastEthernet0/6
!
interface FastEthernet0/7
!
interface FastEthernet0/8
!
interface FastEthernet0/9
!
interface FastEthernet0/10
!
interface FastEthernet0/11
!
interface FastEthernet0/12
!
interface FastEthernet0/13
!
interface FastEthernet0/14
!
interface FastEthernet0/15
!
interface FastEthernet0/16
!
interface FastEthernet0/17
!
interface FastEthernet0/18
!
interface FastEthernet0/19
!
interface FastEthernet0/20
!
interface FastEthernet0/21
!
interface FastEthernet0/22
!
interface FastEthernet0/23
!
interface FastEthernet0/24
!
interface GigabitEthernet0/1
!
interface GigabitEthernet0/2
!
interface Vlan1
 no ip address
 shutdown
!
!
!
!
line con 0
!
line vty 0 4
 login
line vty 5 15
 login
!
!
!
end

switch1 配置

Switch#sh run
Building configuration...

Current configuration : 1237 bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Switch
!
!
!
!
!
spanning-tree mode pvst
spanning-tree extend system-id
!
interface FastEthernet0/1
 description connecting to a pc which is in vlan 20
 switchport access vlan 20
 switchport mode access
!
interface FastEthernet0/2
 description connecting to switch0
 switchport mode trunk
!
interface FastEthernet0/3
!
interface FastEthernet0/4
!
interface FastEthernet0/5
!
interface FastEthernet0/6
!
interface FastEthernet0/7
!
interface FastEthernet0/8
!
interface FastEthernet0/9
!
interface FastEthernet0/10
!
interface FastEthernet0/11
!
interface FastEthernet0/12
!
interface FastEthernet0/13
!
interface FastEthernet0/14
!
interface FastEthernet0/15
!
interface FastEthernet0/16
!
interface FastEthernet0/17
!
interface FastEthernet0/18
!
interface FastEthernet0/19
!
interface FastEthernet0/20
!
interface FastEthernet0/21
!
interface FastEthernet0/22
!
interface FastEthernet0/23
!
interface FastEthernet0/24
!
interface GigabitEthernet0/1
!
interface GigabitEthernet0/2
!
interface Vlan1
 no ip address
 shutdown
!
!
!
!
line con 0
!
line vty 0 4
 login
line vty 5 15
 login
!
!
!
end

路由器 cdp 邻居

Router#sh cdp neighbors 
Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
                  S - Switch, H - Host, I - IGMP, r - Repeater, P - Phone
Device ID    Local Intrfce   Holdtme    Capability   Platform    Port ID
Router#

switch0 cdp 邻居

 Switch#sh cdp neighbors 
Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
                  S - Switch, H - Host, I - IGMP, r - Repeater, P - Phone
Device ID    Local Intrfce   Holdtme    Capability   Platform    Port ID
Switch       Fas 0/2          141            S       2960        Fas 0/2
Router       Fas 0/1          138            R       C2800       Fas 0/0
Router       Fas 0/1          138            R       C2800       Fas 0/0.10
Router       Fas 0/1          138            R       C2800       Fas 0/0.20

switch1 邻居

Switch#sh cdp neighbors 
Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
                  S - Switch, H - Host, I - IGMP, r - Repeater, P - Phone
Device ID    Local Intrfce   Holdtme    Capability   Platform    Port ID
Switch       Fas 0/2          175            S       2960        Fas 0/2
Switch#

路由器不显示任何邻居

2个回答

我认为您的问题可能是您没有在交换机上创建 VLAN。

最简单的方法是作为每个交换机上的全局命令:

VLan 10
 name <vlan name, no spaces, use underscores>
!
VLan 20
 name <vlan name, no spaces, use underscores>
!

对于跨 Vlan 路由的路由器配置似乎是正确的。在两台交换机上创建 Vlan 10 和 Vlan 20 并检查状态。

请确保在连接到 vlan 10 和 vlan 20 的交换机的两台 PC 上正确配置 IP 地址、子网、网关。