三层交换:二层交换+三层转发

不同vlan之间可以通信

实例:

 

Cisco三层交换技术_三层交换

配置3PCip地址

SW2交换机配置

Switch>enable

Switch#conf terminal

Switch(config)#hostname SW2

SW2(config)#vlan 2

SW2(config-vlan)#exit

SW2(config)#vlan 3

SW2(config-vlan)#exit

SW2(config)#interface f0/3

SW2(config-if)#switchport mode access

SW2(config-if)#switchport access vlan 2

SW2(config-if)#exit

SW2(config)#interface f0/2

SW2(config-if)#switchport mode access

SW2(config-if)#switchport access vlan 3

SW2(config-if)#exit

SW2(config)#interface f0/4

SW2(config-if)#switchport mode trunk

SW2(config-if)#end

SW2#show vlan brief

 

VLAN Name                             Status    Ports

---- -------------------------------- --------- -------------------------------

1    default                          active    Fa0/1, Fa0/5, Fa0/6, Fa0/7

                                                Fa0/8, Fa0/9, Fa0/10, Fa0/11

                                                Fa0/12, Fa0/13, Fa0/14, Fa0/15

                                                Fa0/16, Fa0/17, Fa0/18, Fa0/19

                                                Fa0/20, Fa0/21, Fa0/22, Fa0/23

                                                Fa0/24

2    VLAN0002                         active    Fa0/3

3    VLAN0003                         active    Fa0/2

F0/4不在vlan1中,所有trunk添加成功

 

SW3三层交换配置

Switch>enable

Switch#conf terminal

Switch(config)#hostname SW3

SW3(config)#ip routing     #在三层交换上开启路由功能

SW3(config)#interface f0/1

SW3(config-if)#switchport mode trunk

SW3(config-if)#end

SW3#show interfaces f0/1 switchport

Name: Fa0/1

Switchport: Enabled

Administrative Mode: trunk

Operational Mode: trunk

SW3#conf terminal

SW3(config)#vlan 2

SW3(config-vlan)#exit

SW3(config)#vlan 3

SW3(config-vlan)#exit

SW3(config)#interface vlan 1

SW3(config-if)#ip address 192.168.1.1 255.255.255.0

SW3(config-if)#no shutdown

SW3(config-if)#exit

SW3(config)#interface vlan 2

SW3(config-if)#ip address 192.168.2.1 255.255.255.0

SW3(config-if)#no shutdown

SW3(config-if)#exit

SW3(config)#interface vlan 3

SW3(config-if)#ip address 192.168.3.1 255.255.255.0

SW3(config-if)#no shutdown

SW3(config-if)#exit

SW3(config)#interface f0/2

SW3(config-if)#no switchport

SW3(config-if)#ip address 192.168.4.1 255.255.255.0

SW3(config-if)#no shutdown

SW3(config-if)#exit

SW3(config)#ip route 0.0.0.0 0.0.0.0 192.168.4.2

 

路由器上配置

Router>enable

Router#conf terminal

Router(config)#interface f0/0

Router(config-if)#ip address 192.168.4.2 255.255.255.0

Router(config-if)#no shutdown

Router(config-if)#exit

Router(config)#ip route 192.168.1.0 255.255.255.0 192.168.4.1

Router(config)#ip route 192.168.2.0 255.255.255.0 192.168.4.1

Router(config)#ip route 192.168.3.0 255.255.255.0 192.168.4.1

Router(config)#end

Router#show ip interface brief

FastEthernet0/0        192.168.4.2     YES manual up                    up

Router#show ip route

Gateway of last resort is not set

 

S    192.168.1.0/24 [1/0] via 192.168.4.1

S    192.168.2.0/24 [1/0] via 192.168.4.1

S    192.168.3.0/24 [1/0] via 192.168.4.1

C    192.168.4.0/24 is directly connected, FastEthernet0/0

SW3三层交换上查看

SW3#show ip route

Gateway of last resort is 192.168.4.2 to network 0.0.0.0

 

C    192.168.1.0/24 is directly connected, Vlan1

C    192.168.2.0/24 is directly connected, Vlan2

C    192.168.3.0/24 is directly connected, Vlan3

C    192.168.4.0/24 is directly connected, FastEthernet0/2

S*   0.0.0.0/0 [1/0] via 192.168.4.2