场景:电子教室,为了方便管理,使用多套资源,但是虚拟机地址共用一套,一个二层环境 例如:资源-A:192.168.1.1-192.168.1.100,资源-B:192.168.1.1-192.168.1.100 问题:由于VDI-5.3.2以上,VDC配置虚拟机地址会检测该地址是否重复问题,导致无法配置相同地址。
现解决思路:通过主机名的后3位字符串组成网络地址最后一组十进制,通过脚本打到自动配置目的,无需通过VDC进行下放。 脚本内容:内容过于粗糙,大佬勿喷
for /f "delims=0 tokens=*" %%i in ("%computername:~-3%") do set /a hostname_IP=%%i+XX //当前值的增量
for /f "tokens=4,5 delims= " %%j in ('netsh interface show interface ^| find /i "本地连接"') do set local_interface="%%j %%k"
set local_ipaddress=X.X.X.%hostname_IP% //修改为对应的网络前缀
set loacl_gateway=X.X.X.X //修改为对应的网关
set local_netmask=X.X.X.X //修改为对应的掩码
set local_dns=X.X.X.X //修改为对应的DNS
echo %local_interface% static %local_ipaddress% %local_netmask% %loacl_gateway%
netsh interface ip set address %local_interface% static %local_ipaddress% %local_netmask% %loacl_gateway%
netsh interface ip set dnsservers %local_interface% static %local_dns% primary validate=no |