• 实验拓扑

    wKioL1M1br-xwuXsAADXXR1vffQ434.jpg

  • 二层交换机配置

    Switch>
    Switch>en
    Switch#conf t
    Enter configuration commands, one per line.  End with CNTL/Z.
    Switch(config)#vlan 10
    Switch(config-vlan)#exit
    Switch(config)#vlan 20
    Switch(config-vlan)#exit
    Switch(config)#int f 0/1
    Switch(config-if)#switchport access vlan 10
    Switch(config-if)#exit
    Switch(config)#int f 0/3 
    Switch(config-if)#switchport access vlan 20
    Switch(config-if)#exit
    Switch(config)#int f 0/2
    Switch(config-if)#switchport mode trunk 

    Switch(config-if)#
    %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down

    %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to up

    Switch(config-if)#exit
    Switch(config)#exit
    Switch#
    %SYS-5-CONFIG_I: Configured from console by console

    Switch#write
    Building configuration...
    [OK]

     

  • 三层交换机配置

    Switch>en
    Switch#conf t
    Enter configuration commands, one per line.  End with CNTL/Z.
    Switch(config)#int f 0/1
    Switch(config-if)#switchport trunk encapsulation dot1q 
    Switch(config-if)#switchport mode trunk
    Switch(config-if)#exit
    Switch(config)#vlan 10
    Switch(config-vlan)#exit
    Switch(config)#vlan 20
    Switch(config-vlan)#exit
    Switch(config)#interface vlan 10
    Switch(config-if)#
    %LINK-5-CHANGED: Interface Vlan10, changed state to up

    %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up

    Switch(config-if)#ip add 192.168.1.254 255.255.255.0
    Switch(config-if)#exit
    Switch(config)#interface vlan 20
    Switch(config-if)#
    %LINK-5-CHANGED: Interface Vlan20, changed state to up

    %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up

    Switch(config-if)#ip add 192.168.2.254 255.255.255.0
    Switch(config-if)#exit
    Switch(config)#ip routing
    Switch(config)#exit
    Switch#
    %SYS-5-CONFIG_I: Configured from console by console

    Switch#write
    Building configuration...
    [OK]
    Switch#

  • PC0 IP设置:

  • wKioL1M1cUOjvM6TAAC1LplEIEw660.jpg

  • PC1 IP设置:

    wKiom1M1cXujgtUYAACxZ6jHt6E325.jpg

  • 测试:去PC0上PING PC1

    wKioL1M1cY3QD25SAAH90RSCn5w732.jpg