步骤一:配置VLAN网关IP地址,及将相关端口划入相应的VLAN中
S3760#con t
S3760(config)#vlan 2 ----创建VLAN2
S3760(config-vlan)#exit ----退回到全局配置模式下
S3760(config)#vlan 3 ----创建VLAN3
S3760(config-vlan)#exit ----退回到全局配置模式下
S3760(config)#int vlan 2 ----进入配置VLAN2
S3760(config-if)#ip add 192.168.2.1 255.255.255.0 ----设置VLAN2的IP地址
S3760(config-if)#exit ----退回到全局配置模式下
S3760(config)#int vlan 3 ----进入配置VLAN3
S3760(config-if)#ip add 192.168.3.1 255.255.255.0 ----设置VLAN3的IP地址
S3760(config-if)#exit ----退回到全局配置模式下
S3760(config)#int f 0/2 ----进入接口f0/2
S3760(config-if)#switchport access vlan 2 ----设置f0/2口属于VLAN2
S3760(config-if)#exit
S3760(config)#int f 0/3 ----进入接口f0/3
S3760(config-if)#switchport access vlan 3 ----设置f0/3口属于VLAN3
S3760(config-if)#exit
步骤二:配置DHCP server
S3760 (config)#service dhcp ----开启dhcp server功能
S3760 (config)#ip dhcp ping packets 1 ----在dhcp server分配IP时会先去检测将要分配的IP地址是否已有人使用,如果没人使用则分配,若已有人使用则再分配下一个IP
S3760 (config)#ip dhcp excluded-address 192.168.2.1 192.168.2.10
----设置排斥地址为192.168.2.1至192.168.2.10的ip地址不分配给客户端(可选配置)
S3760 (config)#ip dhcp excluded-address 192.168.3.1 192.168.3.10
----设置排斥地址为192.168.3.1至192.168.3.10的ip地址不分配给客户端(可选配置)
S3760 (config)#ip dhcp pool test2 ----新建一个dhcp地址池名为test2
S3760 (dhcp-config)# lease infinite ----租期时间设置为永久
S3760 (dhcp-config)# network 192.168.2.0 255.255.255.0 ----给客户端分配的地址段
S3760 (dhcp-config)# dns-server 202.101.115.55 ----给客户端分配的DNS
S3760(dhcp-config)# default-router 192.168.2.1 ----客户端的网关
S3760(dhcp-config)#exit
S3760(config)#ip dhcp pool test3 ----新建一个dhcp地址池名为test3
S3760(dhcp-config)# lease infinite ----租期时间设置为永久
S3760(dhcp-config)# network 192.168.3.0 255.255.255.0
S3760(dhcp-config)# dns-server 202.101.115.55
S3760(dhcp-config)# default-router 192.168.3.1
S3760(dhcp-config)#end
S3760#wr
图一
DHCP报文的封装如下
E
IP
UDP
BOOTSTRAP
DHCP
FCS
client端口:68
引导程序
server端口:67
下面演示一个实验,针对图一中DHCP的整个过程。
我们用两台路由器实现client与server之间的通信过程,图如下所示:

记住:一定要用以太网接口
关键是进行Server端的配置 假设下放的网段为10.1.1.0/24
如果Client是一台PC机 直接进入本地连接的属性--->internet(TCP/IP)协议,点击自动获取IP即可。
如果是一台路由器,要进行如下相应配置。
router#conf t
router(config)#no ip domain-lookup
router(config)#line console 0
router(config-line)#exec-timeout 0
router(config-line)#logging synchronous
router(config-line)#hostname R1
R1(config)#hostname R1-Client
R1-Client(config)#int e0/0
R1-Client(config-if)#ip address dhcp
R1-Client(config-if)#no shutdown
R1-Client(config-if)#end
R1-Client#
然后对Server端进行配置
router#conf t
router(config)#no ip domain-lookup
router(config)#line console 0
router(config-line)#exec-timeout 0
router(config-line)#logging synchronous
router(config-line)#hostname R2
R2(config)#hostname R2-Server
R2-Server(config)#int e0/0
R2-Server(config-if)#ip add 10.1.1.2 255.255.255.0 :以太网接口一个IP
R2-Server(config-if)#no shutdown
R2-Server(config)#ip dhcp excluded-address 10.1.1.1 10.1.1.10 :除去不能分配下去的地址,一般预留10个地址
R2-Server(config)#ip dhcp poor levin :生成一个dhcp池,红色部分为dhcp池自起的名字
R2-Server(dhcp-config)#network 10.1.1.0 255.255.255.0 :下放的网段地址
R2-Server(dhcp-config)#default-router 10.1.1.1 :默认的网关或叫默认路由
R2-Server(dhcp-config)#dns-server 202.96.128.68 :查询当地运营商的DNS
R2-Server(dhcp-config)#lease 3 :默认的租用日期是一天,可以自己设置
然后在Client端show ip route显示出网段和网关,即可ping通Server端的10.1.1.2。
在Server端输入命令R2(config)#show ip dhcp binding,显示Server端的绑定表。
以上就是简单的DHCP 的配置。
909

被折叠的 条评论
为什么被折叠?



