下面开始

1,不同VLAN通过三层交换通信 2,配置路由器DHCP功能,使得pc机能够自动获得ip地址

SW1:

SW1#vlan database
SW1(vlan)#vlan 10
SW1(vlan)#vlan 20
SW1(vlan)#vtp domain ccb
SW1(vlan)#vtp server
SW1(config)#interface fa0/1
SW1(config-if)#switchport mode trunk
SW1(config-if)#switchport trunk encapsulation dot1q

SW1(config)#interface fa0/2
SW1(config-if)#switchport mode trunk
SW1(config-if)#switchport trunk encapsulation dot1q

interface Vlan10
 ip address 192.168.10.1 255.255.255.0
!
interface Vlan20
 ip address 192.168.20.1 255.255.255.0
 

 

SW2(config)#interface fa0/1
SW2(config-if)#switchport mode trunk
SW2(config-if)#switchport trunk encapsulation dot1q

SW2#vlan database
SW2(vlan)#vtp domain ccb
SW2(vlan)#vtp client

SW2(config)#interface fa0/0
SW2(config-if)#switchport mode acc
SW2(config-if)#switchport access vlan 10

SW3(config)#interface fa0/2
SW3(config-if)#switchport mode trunk
SW3(config-if)#switchport trunk encapsulation dot1q

SW3#vlan database
SW3(vlan)#vtp domain ccb
SW3(vlan)#vtp client

SW3(config)#interface fa0/0
SW3(config-if)#switchport mode acc
SW3(config-if)#switchport access vlan 20

SW2#sh vlan-switch

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/2, Fa0/3, Fa0/4, Fa0/5
                                                Fa0/6, Fa0/7, Fa0/8, Fa0/9
                                                Fa0/10, Fa0/11, Fa0/12, Fa0/13
                                                Fa0/14, Fa0/15
10   VLAN0010                         active    Fa0/0
20   VLAN0020                         active   
 

SW3#sh vlan-switch

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/1, Fa0/3, Fa0/4, Fa0/5
                                                Fa0/6, Fa0/7, Fa0/8, Fa0/9
                                                Fa0/10, Fa0/11, Fa0/12, Fa0/13
                                                Fa0/14, Fa0/15
10   VLAN0010                         active   
20   VLAN0020                         active    Fa0/0
下面在PC上配上ip地址测试vlan间的路由

PC1(config)#no ip routing
PC1(config)#interface fa0/0
PC1(config-if)#ip add 192.168.10.11 255.255.255.0
PC1(config)#ip default-gateway 192.168.10.1

PC2(config)#no ip routing
PC2(config)#interface fa0/0
PC2(config-if)#ip add 192.168.20.11 255.255.255.0
PC2(config)#ip default-gateway 192.168.20.1

PC1#ping 192.168.20.11

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.20.11, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 24/54/104 ms

vlan间已经通过三层交换通信,下面在路由器上配置DHCP,让PC机子自动获取IP,排除部分地址,更能看出效果

routerA:

ip dhcp excluded-address 192.168.10.1 192.168.10.10
ip dhcp excluded-address 192.168.20.1 192.168.20.10
!        
ip dhcp pool vlan10
   network 192.168.10.0 255.255.255.0
   default-router 192.168.10.1
!
ip dhcp pool vlan20
   network 192.168.20.0 255.255.255.0
   default-router 192.168.20.1
!

路由器和三层交换机启用ospf路由协议,PC和路由器之间能够通信

routerA:
interface FastEthernet0/0
 ip address 192.168.30.1 255.255.255.0
 duplex auto
 speed auto
!
router ospf 10
 log-adjacency-changes
 network 192.168.30.0 0.0.0.255 area 0

SW1:

interface FastEthernet0/0
 no switchport
 ip address 192.168.30.2 255.255.255.0

router ospf 10
 log-adjacency-changes
 network 192.168.10.0 0.0.0.255 area 0
 network 192.168.20.0 0.0.0.255 area 0
 network 192.168.30.0 0.0.0.255 area 0

 

PC1#ping 192.168.30.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.30.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 20/252/1060 ms

需要把PC设置成自动获取IP

PC1(config)#interface fa0/0
PC1(config-if)#no ip add
PC1(config-if)#ip add dhcp
PC1(config-if)#exit
PC1(config)#no ip default-gateway
 

PC2(config)#interface fa0/0
PC2(config-if)#no ip add
PC2(config-if)#ip add dhcp
PC2(config-if)#exit
PC2(config)#no ip default-gateway
 

上面已经配置了,但是不能获得IP地址,因为还需要ip helper-address 命令,因为三层交换机隔离广播,所以需要指定请求地址

SW1(config)#interface vlan 10
SW1(config-if)#ip helper-address 192.168.30.1

SW2(config)#interface vlan 20
SW2(config-if)#ip helper-address 192.168.30.1

下面看一下 PC1和PC2 获得的IP地址

PC1#sh ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.10.11   YES DHCP   up                    up

PC2#sh ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.20.11   YES DHCP   up                    up  

PC1#ping 192.168.20.11

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.20.11, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 28/272/1168 ms