![我无法设置以下 Netsh 设置,因为该对象已存在](https://linux22.com/image/1448462/%E6%88%91%E6%97%A0%E6%B3%95%E8%AE%BE%E7%BD%AE%E4%BB%A5%E4%B8%8B%20Netsh%20%E8%AE%BE%E7%BD%AE%EF%BC%8C%E5%9B%A0%E4%B8%BA%E8%AF%A5%E5%AF%B9%E8%B1%A1%E5%B7%B2%E5%AD%98%E5%9C%A8.png)
我使用Netsh int ipv6 show int
终端,结果:
1 50 4294967295 connected Loopback Pseudo-Interface 1
11 10 1500 connected Local connection
当我想使用以下任务时:
Netsh interface ipv6 set interface 11 advertise=enabled
Netsh interface ipv6 add route 1024::/64 11 publish=yes
Netsh interface ipv6 add route fda8:06c3:ce53:a890::/64 11 publish=yes*
当我尝试第 3 行时,写的内容是该对象已经存在。这就是我无法运行此任务的原因。我该如何设置这些设置?
答案1
第三个命令正在尝试添加具有特定设置的路线。
该路线已存在。
鉴于此,显而易见的选择是改变现有路线使用相同的特定设置。使用netsh interface ipv6 set route ... publish=yes
即可。
答案2
function set-ip-static ([string]$ip, [string]$strMask, [string]$gateway, [string]$dns1, [string]$dns2, [string]$networkInterface) {
netsh interface ipv4 set address name=$networkInterface static $ip $strMask $gateway 1
netsh interface ipv4 delete dnsservers name=$networkInterface all validate=no
netsh interface ipv4 set dns name=$networkInterface static addr=$dns1 validate=no
netsh interface ipv4 add dnsservers name=$networkInterface addr=$dns2 index=2 validate=no
}
function set-ip-whatever {
$ip = "192.168.201.25"
$strMask = "255.255.255.0"
$gateway = "192.168.201.254"
$dns1 = "8.8.8.8"
$dns2 = "8.8.4.4"
$networkInterface = "Wi-Fi 2"
set-ip-static $ip $strMask $gateway $dns1 $dns2 $networkInterface
}