实验拓扑
步骤:
第一步
首先打开SW1,配置它vlan信息
SW1#conf t
Enter configuration commands, one per line. End with
CNTL/Z.
SW1#vlan database
SW1(vlan)#vlan 10 name ccna
VLAN 10 added:
Name: ccna
SW1(vlan)#vlan 20 name ccnp
VLAN 20 added:
Name: ccnp
SW1(vlan)#exit
APPLY completed.
Exiting....
SW1#conf t
Enter configuration commands, one per line. End with
CNTL/Z.
SW1(config)#int f0/1
SW1(config-if)#switchport access vlan 10
SW1(config-if)#int f0/2
SW1(config-if)#switchport access vlan 20
SW1(config-if)#int f0/0
SW1(config-if)#switchport mode trunk
*Mar 1 00:05:15.851: %DTP-5-TRUNKPORTON: Port Fa0/0 has
become dot1q trunk
第二步
对DHCPServer的配置
DHCPServer#conf t
Enter configuration commands, one per line. End with
CNTL/Z.
DHCPServer(config)#int f0/0
DHCPServer(config-if)#no shutdown
先打开它的物理接口
*Mar 1 00:06:12.583: %LINK-3-UPDOWN: Interface
FastEthernet0/0, changed state to up
*Mar 1 00:06:13.583: %LINEPROTO-5-UPDOWN: Line protocol on
Interface FastEthernet0/0, changed state to up
DHCPServer(config-if)#int f0/0.10
创建一个子接口,用来单臂路由
DHCPServer(config-subif)#encapsulation dot1Q
10 一定要记住先对这个端口进行数据封装,再配置地址
DHCPServer(config-subif)#ip add 192.168.10.1
255.255.255.0
DHCPServer(config-subif)#int f0/0.20
DHCPServer(config-subif)#encapsulation dot1Q 20
DHCPServer(config-subif)#ip add 192.168.20.1
255.255.255.0
DHCPServer(config-subif)#exit
DHCPServer(config)#service dhcp
打开dhcp服务
DHCPServer(config)#ip dhcp pool vlan_10
创建vlan10的地址池
DHCPServer(dhcp-config)#network 192.168.10.0 /24
DHCPServer(dhcp-config)#dns-server 8.8.8.8
DHCPServer(dhcp-config)#lease 0 10 30
DHCPServer(dhcp-config)#default-router 192.168.10.1
DHCPServer(dhcp-config)#ip dhcp pool vlan_20
DHCPServer(dhcp-config)#network 192.168.20.0 /24
DHCPServer(dhcp-config)#dns-server 8.8.8.8
DHCPServer(dhcp-config)#lease 0 2
DHCPServer(dhcp-config)#default-router 192.168.20.1
DHCPServer(dhcp-config)#exit
DHCPServer(config)#ip dhcp excluded-address 192.168.10.1
192.168.10.10
DHCPServer(config)#ip dhcp excluded-address 192.168.20.1
192.168.20.6
DHCPServer(config)#end
DHCPServer#show ip dhcp pool
Pool vlan_10 :
Utilization mark (high/low) : 100 / 0
Subnet size (first/next) : 0
/ 0
Total
addresses : 254
Leased
addresses : 0
Pending
event : none
1 subnet is currently in the pool :
Current index IP
address
range Leased addresses
192.168.10.1 192.168.10.1 -
192.168.10.254 0
Pool vlan_20 :
Utilization mark (high/low) : 100 / 0
Subnet size (first/next) : 0
/ 0
Total
addresses : 254
Leased
addresses : 0
Pending
event : none
1 subnet is currently in the pool :
Current index IP
address
range Leased addresses
192.168.20.1 192.168.20.1 - 192.168.20.254 0
DHCPServer#
第三步
对PC1、PC2的配置
PC1#conf t
Enter configuration commands, one per line. End with
CNTL/Z.
PC1(config)#no ip routing
PC1(config)#no ip do lo
PC1(config)#int f0/0
PC1(config-if)#ip add dhcp
PC1(config-if)#no shutdown
*Mar 1 00:15:20.463: %LINK-3-UPDOWN: Interface
FastEthernet0/0, changed state to up
*Mar 1 00:15:21.463: %LINEPROTO-5-UPDOWN: Line protocol on
Interface FastEthernet0/0, changed state to up
*Mar 1 00:15:33.435: %DHCP-6-ADDRESS_ASSIGN: Interface
FastEthernet0/0 assigned DHCP address 192.168.10.11, mask
255.255.255.0, hostname PC1
PC1(config-if)#end
PC1#show ip int b
Interface
IP-Address OK? Method Status Protocol
FastEthernet0/0
192.168.10.11 YES
DHCP up up
PC2
PC2#conf t
Enter configuration commands, one per line. End with
CNTL/Z.
PC2(config)#no ip routing
PC2(config)#no ip do lo
PC2(config)#int f0/0
PC2(config-if)#ip add dhcp
PC2(config-if)#no shutdown
PC2(config-if)#end
*Mar 1 00:17:51.691: %SYS-5-CONFIG_I: Configured from
console by console
*Mar 1 00:17:51.735: %LINK-3-UPDOWN: Interface
FastEthernet0/0, changed state to up
*Mar 1 00:17:52.735: %LINEPROTO-5-UPDOWN: Line protocol on
Interface FastEthernet0/0, changed state to up
PC2#show ip int b
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 192.168.20.7 YES DHCP up up
第四步
我们可以对它们之间能否通信进行测试
PC2#ping 192.168.20.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.20.1, timeout is 2
seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max =
20/231/1028 ms
PC2#ping 192.168.10.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.10.1, timeout is 2
seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max =
16/32/56 ms
PC2#ping 192.168.10.11
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.10.11, timeout is 2
seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max =
20/38/60 ms
PC2#