实验拓扑图:

 

实验要求:

Router上配置单臂路由,实现不同vlan之间的通信。

实验过程

 

1.switch上划分两个vlan,并把f0/2划分进vlan10,把f0/3划分进vlan20

Router>en

Router#config t

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#no ip domain-lookup

Router(config)#line console 0

Router(config-line)#no exec-timeout

Router(config-line)#loggin syn

Router(config-line)#exit

Router(config)#end

Router#vlan database  //创建vlan

Router(vlan)#vlan 10

VLAN 10 added:

    Name: VLAN0010

Router(vlan)#vlan 20

VLAN 20 added:

    Name: VLAN0020

Router(vlan)#exit

APPLY completed.

Exiting....

Router#config t

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#interface f0/2  

Router(config-if)#switchport access vlan 10  //划分接口进vlan

 

Router(config-if)#interface f0/3

Router(config-if)#switchport access vlan 20

Router(config-if)#interface f0/1

Router(config-if)#switchport mode trunk  //把连接路由器的接口封装成trunk

Router(config-if)#end

2.分别配置pc1pc2IP地址

pc1(config)#interface f0/0

pc1(config-if)#no shut

pc1(config-if)#ip add 172.16.0.1 255.255.255.0

pc1(config-if)#exit

pc1(config)#ip default-gateway 172.16.0.254  //做单臂路由的实验,pc需要指定默认网关

pc2(config)#interface f0/0

pc2(config-if)#no shut

pc2(config-if)#ip add 192.168.0.1 255.255.255.0

pc2(config-if)#exit

pc2(config)#ip default-gateway 192.168.0.254

3.Router上配置单臂路由

Router>en

Router#config t

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#no ip domain-lookup

Router(config)#line console 0

Router(config-line)#no exec-timeout

Router(config-line)#loggin syn

Router(config-line)#exit

Router(config)#interface f0/0

Router(config-if)#no shut

Router(config-if)#exit

Router(config)#interface f0/0.1  //进入f0/0的子接口

Router(config-subif)#encapsulation dot1q 10  //封装dot1q,允许vlan10通过

Router(config-subif)#ip add 172.16.0.254 255.255.255.0  //配置网关地址

Router(config-subif)#exit

Router(config)#interface f0/0.2

Router(config-subif)#encapsulation dot1q 20

Router(config-subif)#ip add 192.168.0.254 255.255.255.0

Router(config-subif)#end

4.测试pc1能否pingpc2

pc1#ping 192.168.0.1

 

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 192.168.0.1, timeout is 2 seconds:

!!!!!   //单臂路由可以实现不同vlan之间的通信

Success rate is 100 percent (5/5), round-trip min/avg/max = 12/36/76 ms

pc2#ping 172.16.0.1

 

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 172.16.0.1, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 12/38/64 ms