其实DHCP一般都有地址保留地址功能,可以让客户端分配到一个固定的IP地址,在网络使用DHCP的情况下,这能给内网管理带来了极大的方便。不过保留地址配置起来就有点麻烦,要配置的数量少还好说,要是多的话,可就是个麻烦事啊。这中麻烦事就交给批处理吧。哈哈
本文介绍的环境为Windows Server 2003 R2,同样适用于Server 2008/2012
1.首先要统计好内网所有客户端的IP地址、MAC地址。
部门 | 姓名 | IP地址 | MAC地址 |
管理层 | 梁晓婷 | 192.168.1.10 | 00-0b-2f-49-d6-65 |
梁文婷 | 192.168.1.11 | 00-e0-66-02-f5-4c | |
曾春梅 | 192.168.1.12 | 00-e0-66-06-07-5d | |
卢燕璇 | 192.168.1.13 | 00-e0-66-06-4a-37 | |
林晓洁 | 192.168.1.14 | 00-e0-66-02-29-5e | |
杨嘉华 | 192.168.1.15 | 00-e0-66-17-16-41 | |
服务部 | 李薇 | 192.168.1.16 | 00-e0-66-02-e8-86 |
梁雨婷 | 192.168.1.17 | 00-e0-66-02-dd-70 | |
潘瑞月 | 192.168.1.18 | 00-e0-4c-41-14-f1 | |
陈慧娟 | 192.168.1.19 | 00-e0-66-02-f4-22 | |
刘美虹 | 192.168.1.20 | 00-e0-66-06-0a-2a | |
商务部 | 翟业江 | 192.168.1.21 | 00-e0-66-02-f3-4c |
林立英 | 192.168.1.22 | 00-e0-66-02-db-a2 | |
推广 | 苏文锋 | 192.168.1.23 | 54-04-a6-66-bd-bd |
钟文 | 192.168.1.24 | 00-30-67-ba-0c-ac | |
邓雪凤 | 192.168.1.25 | 00-e0-62-0b-1f-6c | |
张贵伟 | 192.168.1.26 | bc-ae-c5-5d-65-c0 |
2.根据统计好每个客户端使用人的名字,MAC地址,要分配的IP地址,电脑使用人的名字,做成一个批处理文件。以下面的批处理为例,192.168.1.249为DHCP服务器,192.168.1.0为作用域,192.168.1.12为地址,00e06602f54c这个是MAC地址,PC012是名称,后面的为电脑使用人。这条命令就是把192.168.1.12固定分配给00e06602f54c的机器
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.12 00e06602f54c PC012 刘志仙 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.13 00e06602d6e9 PC013 梁文婷 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.14 00e06606075d PC014 曾春梅 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.15 00e06602e5ea PC015 谭学锋 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.16 00e066064e4d PC016 陈涵 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.17 00e06602f190 PC017 李煦明 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.18 00e06606076b PC018 潘辉 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.19 00e06602df8b PC019 叶健坤 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.20 00e066064e4f PC020 谢秀红 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.21 00e06602f355 PC021 李诚原 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.22 00e04c4111ac PC022 黄丽娟 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.23 00e06602f03c PC023 刘彩帆 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.24 00e0660645ce PC024 李量子 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.25 00e0660645d0 PC025 邓国花 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.26 00e06602f193 PC026 张明航 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.27 00e0620b228f PC027 钟娟 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.28 00e06602deca PC028 宁雅丽 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.29 00e06602f404 PC029 谭丹萍 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.30 00e0620b2320 PC030 李薇 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.31 00e06602f422 PC031 钟梅 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.32 00e066064a37 PC032 卢燕璇 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.33 00e04c4114f1 PC033 刘裕玲 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.34 000b2f49d665 PC034 梁晓婷 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.35 00e06602e886 PC035 刘扬凤 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.36 00e0620b2039 PC036 邓小芳 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.37 00e06619def4 PC037 莫汝兰 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.38 00e0620b226d PC038 漆浪 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.39 00e06602b01e PC039 彭雅娜 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.40 00e04c4111b3 PC040 冯晶晶 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.41 00e06602df8c PC041 周国香 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.42 00e0660d71d9 PC042 邱瑾 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.43 00e06619dee9 PC043 陈永行 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.44 00e0660652cd PC044 夏依华 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.45 bcaec55d65de PC045 黄国锐 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.46 bcaec55d65c0 PC046 张贵伟 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.47 20cf3020da33 PC047 蔡泽鑫 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.48 00E04CD92540 PC048 李祥 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.49 00e04c4111a8 PC049 罗露 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.50 00e0620b1f6c PC050 关开杰 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.51 00e0620b2280 PC051 谢康辉 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.52 00e04cd91f45 PC052 王孝平 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.53 00e06602d9f5 PC053 许振飞 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.54 00e06602e014 PC054 曹军 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.55 00e06602f34c PC055 翟业江 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.56 00e04c411186 PC056 赵安荣 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.57 00e06619e09c PC057 马燕飞 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.58 00e06602f1bc PC058 谢亚辉 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.59 00e06619df0d PC059 陈开 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.60 00e06602decd PC060 薛忠 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.61 00e06602ddd5 PC061 冯满珍 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.62 00e04c096398 PC062 周柳 BOTH
netsh dhcp server 192.168.1.249 scope 192.168.1.0 add reservedip 192.168.1.63 00e06602dba2 PC063 谢禄强 BOTH
这个批处理的命令是通过Netsh DHCP server scope add reservedip命令实现的
关于命令的解释摘自微软官网
===================================================================================
add reservedip
保留一个 IP 地址供当前作用域中指定的媒体访问控制 (MAC) 地址使用。
语法
add reservedipReservedIPMACAddress [ClientName] [ClientComment] [{DHCP | BOOTP | BOTH}]
参数
ReservedIP
必需。指定要保留的 IP 地址。
MACAddress
必需。指定要与保留的 IP 地址关联的物理硬件或 MAC 地址。
ClientName
指定要与保留的客户端项关联的客户端名称。如果未指定,将不会有客户端名称与该保留的客户端项关联。
ClientComment
指定要与保留的客户端项关联的客户端注释。如果未指定,将不会有客户端注释与该保留的客户端项关联。
{DHCP | BOOTP| BOTH}
指定要与保留的客户端项关联的客户端类型。默认值为 DHCP。
====================================================================================
3.在服务器上先建立好作用域,然后再运行批处理,喝杯咖啡等着完成就行了