1.安装dhcp服务器角色,这样在netsh下才会有dhcp上下文
2.编写配置dhcp的脚本
从命令行运行netsh有两种语法:
比如要获取已经配置的网络接口列表
1.写全
netsh -r remotecomputername interface ipv4 show interface
其中:-r remotecomputername 是指定要操作的远程主机或本机的计算机名,interface ipv4 是netsh下的上下文,show interface 是interface ipv4 下获取网络接口列表的命令。
2.netsh -c context -r remotecomputername command
其中,context为待操作的上下文标识符,remotecomputername 是指定要操作的远程主机或本机的计算机名,command 是待执行的命令。
netsh -c "interface ipv4" -r remotecomputer show interfaces
有了以上的了解后,我们在编写dhcp的脚本时,使用第二种写法,这样的脚本简单,方便指定远程主机,不会写死。
要求: 建立作用域192.168.1.0 名字为mainscope,备注为primaryscope 建立地址池,分发的ip范围为192.168.1.1-254,其中1-25的ip排除不能分配
批处理脚本dhcp_scope_192.168.1.0.bat
add scope 192.168.1.0 255.255.255.0 mainscope primaryscope scope 192.168.1.0 add iprange 192.168.1.1 192.168.1.254 scope 192.168.1.0 add excluderange 192.168.1.1 192.168.1.25 scope 192.168.1.0 set state 1
执行时:
netsh -c "dhcp server" -r remotecomputer -f dhcp_scope_192.168.1.0.bat
其中,dhcp server是上下文,-f dhcp_scope_192.168.1.0.bat是执行的脚本文件或网络路径。
要删除建立的作用域:
netsh -c "dhcp server" -r remotecomputer del scope 192.168.1.0 dhcpfullforce
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论