Router 作为 DHCP 服务器:(如果服务器与客户端不在一个网段)
(依然是需要 DHCP-relay技术的)
1、启动DHCP服务
service dhcp
2、排除不自动分配的DHCP地址
ip dhcp excluded-address 192.168.1.1 192.168.1.10
3、创建DHCP地址池
ip dhcp pool A
network 192.168.1.0 255.255.255.0 //指定自动分配的网段
default-router 192.168.1.254 //指定分配的网关
dns-server 8.8.8.8 //指定自动分配的 DNS 服务器
4、验证与测试
show ip dhcp binding // 查看分配以后的IP地址
拓扑图:
相关命令
路由R
Router>en
Router#configure terminal
Enter configuration commands, one per line. End with
CNTL/Z.
Router(config)#int gi0/0
Router(config-if)#no shu
Router(config-if)#ip address 10.10.1.1 255.255.255.0
Router(config-if)#ex
Router(config)#ip routing
Router(config)#ip route 192.168.10.0 255.255.255.0
10.10.1.2
Router(config)#ip route 192.168.20.0 255.255.255.0
10.10.1.2
Router(config)#service dhcp
Router(config)#ip dhcp excluded-address 192.168.10.3
192.168.10.10
Router(config)#ip dhcp pool a
Router(dhcp-config)#network 192.168.10.0 255.255.255.0
Router(dhcp-config)#default-router 192.168.10.1
Router(dhcp-config)#dns-server 8.8.8.8
Router(dhcp-config)#ex
Router(config)#ip dhcp pool b
Router(dhcp-config)#network 192.168.20.0 255.255.255.0
Router(dhcp-config)#default-router 192.168.20.1
Router(dhcp-config)#dns-server 8.8.8.8
Router(dhcp-config)#ex
Router(config)#int gi0/0
Router(config-if)#no shu
Router(config-if)#ip address 10.10.1.1 255.255.255.0
Router(config-if)#ex
Router(config)#ip routing
Router(config)#ip route 192.168.10.0 255.255.255.0
10.10.1.2
Router(config)#ip route 192.168.20.0 255.255.255.0
10.10.1.2
Router(config)#service dhcp
Router(config)#ip dhcp excluded-address 192.168.10.3
192.168.10.10
Router(config)#ip dhcp pool a
Router(dhcp-config)#network 192.168.10.0 255.255.255.0
Router(dhcp-config)#default-router 192.168.10.1
Router(dhcp-config)#dns-server 8.8.8.8
Router(dhcp-config)#ex
Router(config)#ip dhcp pool b
Router(dhcp-config)#network 192.168.20.0 255.255.255.0
Router(dhcp-config)#default-router 192.168.20.1
Router(dhcp-config)#dns-server 8.8.8.8
Router(config)#exit
多层交换机
Switch>en
Switch#configure t
Enter configuration commands, one per line. End with
CNTL/Z.
Switch(config)#vlan 10
Switch(config-vlan)#vlan 20
Switch(config-vlan)#ex
Switch(config)#int f0/3
Switch(config-if)#switchport trunk encapsulation dot1q
Switch(config-if)#switchport mode trunk
Switch(config-if)#ex
Switch(config)#int f0/4
Switch(config-if)#switchport trunk encapsulation dot1q
Switch(config-if)#switchport mode trunk
Switch(config-if)#ex
Switch(config)#int vlan 10
Switch(config-if)#ip add 192.168.10.1 255.255.255.0
Switch(config-if)#ip help
Switch(config-if)#ip helper-address 10.10.1.1
Switch(config-if)#ex
Switch(config)#int vlan 20
Switch(config-if)#ip address 192.168.20.1 255.255.255.0
Switch(config-if)#ip helper-address 10.10.1.1
Switch(config-if)#ex
Switch(config)#service dhcp
Switch(config)#int vlan 1
Switch(config-if)#no shu
Switch(config-if)#ip address 10.10.1.2 255.255.255.0
Switch(config-if)#ex
Switch(config)#int f0/4
Switch(config-if)#no shu
交换机
Switch>en
Switch#configure terminal
Enter configuration commands, one per line. End with
CNTL/Z.
Switch(config)#vlan 10
Switch(config-vlan)#vlan 20
Switch(config-vlan)#ex
Switch(config)#int f0/1
Switch(config-if)#sw mo a
Switch(config-if)#sw a v 10
Switch(config-if)#ex
Switch(config)#int f0/2
Switch(config-if)#sw mo a
Switch(config-if)#sw a
% Incomplete command.
Switch(config-if)#sw a v 20
Switch(config-if)#exi
Switch(config)#int f0/3
Switch(config-if)#sw mo tr
本文转自 linuxpp 51CTO博客,原文链接:http://blog.51cto.com/13505118/2050460,如需转载请自行联系原作者