cmd 配置dchp服务器

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

 

转载于:https://www.cnblogs.com/feiquan/p/10641102.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值