en
进入配置模式:
conf t
vtp mode server
vtp domain wencell(其他与之相连的交换机都会学习到vlan)
vlan 10 (创建名为10的vlan)
exit
vlan 20
exit
vlan 30
exit
vlan 40
exit
将每个端口加入到VLAN:
int f0/1
switchport access vlan 10
exit
显示vlan 信息:do sh vlan b
int range f0/4
switchport mode trunk
exit
如果是多个出接口:
int range f0/3-5
sw m t
exit
en
conf t
ip routing 开启三层路由功能
no ip routing 关闭三层路由功能
int f0/0.1
r1(config-subif)#encapsulation dot1Q 10
r1(config-subif)#ip add 10.1.1.254 255.255.255.0
r1(config-subif)#no sh
r1(config-subif)#exit
int f0/0.2
r1(config-subif)#encapsulation dot1Q 10
r1(config-subif)#ip add 10.1.1.254 255.255.255.0
r1(config-subif)#no sh
r1(config-subif)#exit
int f0/0.3
r1(config-subif)#encapsulation dot1Q 10
r1(config-subif)#ip add 10.1.1.254 255.255.255.0
r1(config-subif)#no sh
r1(config-subif)#exit
(开启总接口):
r1(config)#int f0/0
r1(config-if)#no sh
r1(config-if)#exit
conf t (以下命令,直接复制粘贴)
ip dhcp excluded-address 10.1.1.1 10.1.1.99(排除的Ip地址)
ip dhcp pool v10 (地址池的名字是v10)
network 10.1.1.0 255.255.255.0
default-router 10.1.1.254
dns-server 40.1.1.1
ip dhcp excluded-address 20.1.1.1 20.1.1.99
ip dhcp pool v20
network 20.1.1.0 255.255.255.0
default-router 20.1.1.254
dns-server 40.1.1.1
ip dhcp excluded-address 30.1.1.1 30.1.1.99
ip dhcp pool v30
network 30.1.1.0 255.255.255.0
default-router 30.1.1.254
dns-server 40.1.1.1
r1(config)#do sh run
点击每台pc 可以自动获取ip
no ip dhcp excluded-address 10.1.1.1 10.1.1.99
no ip dhcp pool v10
no ip dhcp excluded-address 10.1.1.1 10.1.1.99
no ip dhcp excluded-address 20.1.1.1 20.1.1.99
no ip dhcp excluded-address 30.1.1.1 30.1.1.99
no ip dhcp pool v10
no ip dhcp pool v20
no ip dhcp pool v30
(以上命令,直接粘贴复制到en模式下就行)
写完每一条后点击添加,不要点保存,最后不要忘了启用
配置dhcp中继,这样不用以广播的形式也能为pc分配ip
在路由器上配置dhcp帮助:
int f0/0.1 (该接口需要被帮助)
ip helper-address DHCP服务器的IP
exit
int f0/0.2 (该接口需要被帮助)
ip helper-address 40.1.1.1
exit
int f0/0.3 (该接口需要被帮助)
ip helper-address 40.1.1.1
exit