交换机的配置:
Switch>enable
Switch#vlan database
% Warning: It is recommended to configure VLAN from config mode,
as VLAN database mode is being deprecated. Please consult user
documentation for configuring VTP/VLAN in config mode.
Switch#vlan database
% Warning: It is recommended to configure VLAN from config mode,
as VLAN database mode is being deprecated. Please consult user
documentation for configuring VTP/VLAN in config mode.
Switch(vlan)#vlan 10 name v10
VLAN 10 modified:
Name: v10
Switch(vlan)#vlan 20 name v20
VLAN 20 modified:
Name: v20
Switch(vlan)#vlan 30 name v30
VLAN 30 modified:
Name: v30
Switch(vlan)#exit
APPLY completed.
Exiting....
Switch#
Switch(config)#ip dhcp pool vlan10 *设置相应的VLAN
Switch(dhcp-config)#default-router 192.168.1.254 *设置该地址池的默认网关
Switch(dhcp-config)#network 192.168.1.0 255.255.255.0 *设置分配的地址池
Switch(dhcp-config)#dns-server 202.1.1.1 *设置该地址池的默认DNS地址。
Switch(dhcp-config)#ip dhcp pool vlan20
Switch(dhcp-config)#default-router 192.168.2.254
Switch(dhcp-config)#network 192.168.2.0 255.255.255.0
Switch(dhcp-config)#dns-server 202.1.1.2
Switch(dhcp-config)#ip dhcp pool vlan30
Switch(dhcp-config)#default-router 192.168.3.254
Switch(dhcp-config)#network 192.168.3.0 255.255.255.0
Switch(dhcp-config)#exit
Switch(config)#ip dhcp excluded-address 192.168.3.2 192.168.3.10 *设置保留地址,此条命令不是保留192.168.3.2与192.168.3.10两个地址,而是保留192.168.3.2至192.168.3.10的全部地址。
Switch(config)#ip dhcp excluded-address 192.168.2.1 *保留单一的一个地址。
Switch(config)#
Switch(config)#interface range f 0/1 -24
Switch(config-if-range)#spanning-tree portfast
Switch(config-if-range)#exit
Switch(config)#int f 0/1
Switch(config-if)#switchport access vlan 10
Switch(config-if)#int f 0/2
Switch(config-if)#switchport access vlan 20
Switch(config-if)#int range f 0/3 -5
Switch(config-if-range)#switchport access vlan 30
Switch(config-if-range)#exit
Switch(config)#
Switch(config)#interface vlan 10
VLAN 10 modified:
Name: v10
Switch(vlan)#vlan 20 name v20
VLAN 20 modified:
Name: v20
Switch(vlan)#vlan 30 name v30
VLAN 30 modified:
Name: v30
Switch(vlan)#exit
APPLY completed.
Exiting....
Switch#
Switch(config)#ip dhcp pool vlan10 *设置相应的VLAN
Switch(dhcp-config)#default-router 192.168.1.254 *设置该地址池的默认网关
Switch(dhcp-config)#network 192.168.1.0 255.255.255.0 *设置分配的地址池
Switch(dhcp-config)#dns-server 202.1.1.1 *设置该地址池的默认DNS地址。
Switch(dhcp-config)#ip dhcp pool vlan20
Switch(dhcp-config)#default-router 192.168.2.254
Switch(dhcp-config)#network 192.168.2.0 255.255.255.0
Switch(dhcp-config)#dns-server 202.1.1.2
Switch(dhcp-config)#ip dhcp pool vlan30
Switch(dhcp-config)#default-router 192.168.3.254
Switch(dhcp-config)#network 192.168.3.0 255.255.255.0
Switch(dhcp-config)#exit
Switch(config)#ip dhcp excluded-address 192.168.3.2 192.168.3.10 *设置保留地址,此条命令不是保留192.168.3.2与192.168.3.10两个地址,而是保留192.168.3.2至192.168.3.10的全部地址。
Switch(config)#ip dhcp excluded-address 192.168.2.1 *保留单一的一个地址。
Switch(config)#
Switch(config)#interface range f 0/1 -24
Switch(config-if-range)#spanning-tree portfast
Switch(config-if-range)#exit
Switch(config)#int f 0/1
Switch(config-if)#switchport access vlan 10
Switch(config-if)#int f 0/2
Switch(config-if)#switchport access vlan 20
Switch(config-if)#int range f 0/3 -5
Switch(config-if-range)#switchport access vlan 30
Switch(config-if-range)#exit
Switch(config)#
Switch(config)#interface vlan 10
%LINK-5-CHANGED: Interface Vlan10, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on 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)#interface vlan 20
Switch(config-if)#interface vlan 20
%LINK-5-CHANGED: Interface Vlan20, changed state to up
Switch(config-if)#ip add 192.168.2.254 255.255.255.0
Switch(config-if)#interface vlan 30
Switch(config-if)#ip add 192.168.2.254 255.255.255.0
Switch(config-if)#interface vlan 30
%LINK-5-CHANGED: Interface Vlan30, changed state to up
Switch(config-if)#ip add 192.168.3.254 255.255.255.0
Switch(config-if)#exit
Switch(config-if)#ip add 192.168.3.254 255.255.255.0
Switch(config-if)#exit
Switch(config)#ip routing
区域颜色所作配置解释:
创建VLAN
配置DHCP分配地址池
将各接口划分到相应的VLAN
配置DHCP分配地址池
将各接口划分到相应的VLAN
配置VLAN接口IP
下面我们来看一下DHCP分配后的结果:
PC0
PC1
PC2
PC3
PC4
注意分配出来的IP地址的结果:
pc0是被划分到vlan10。
vlan10我们做的DHCP分配方法为:
Switch(config)#ip dhcp pool vlan10
Switch(dhcp-config)#default-router 192.168.1.254
Switch(dhcp-config)#network 192.168.1.0 255.255.255.0
Switch(dhcp-config)#dns-server 202.1.1.1
Switch(dhcp-config)#default-router 192.168.1.254
Switch(dhcp-config)#network 192.168.1.0 255.255.255.0
Switch(dhcp-config)#dns-server 202.1.1.1
pc1是被划分到vlan20。
vlan10我们做的DHCP分配方法为:
Switch(dhcp-config)#ip dhcp pool vlan20
Switch(dhcp-config)#default-router 192.168.2.254
Switch(dhcp-config)#network 192.168.2.0 255.255.255.0
Switch(dhcp-config)#dns-server 202.1.1.2
Switch(dhcp-config)#default-router 192.168.2.254
Switch(dhcp-config)#network 192.168.2.0 255.255.255.0
Switch(dhcp-config)#dns-server 202.1.1.2
并做了192.168.2.1的地址保留,所以PC的分配IP为192.168.2.2
pc2 pc3 pc4是被划分到vlan30。
vlan10我们做的DHCP分配方法为:
Switch(dhcp-config)#ip dhcp pool vlan30
Switch(dhcp-config)#default-router 192.168.3.254
Switch(dhcp-config)#network 192.168.3.0 255.255.255.0
Switch(dhcp-config)#exit
Switch(dhcp-config)#default-router 192.168.3.254
Switch(dhcp-config)#network 192.168.3.0 255.255.255.0
Switch(dhcp-config)#exit
此处我们并没有设置DNS,所以分配出来的结果dns-server项为0.0.0.0
而且我们保留了192.168.3.2-192.168.3.10的所有地址。
所以分配出来的ip分别为192.168.3.1 192.168.3.11 192.168.3.12