配置windows loopback ip的相关命令整理如下
代码语言:powershell复制#查看当前配置
netsh interface ipv4 show address 1
netsh interface ipv4 show interface
netsh interface ipv4 show addresses
假设vip是192.168.1.3
【高版本系统用powershell配置】
#配置
New-NetIPAddress -InterfaceAlias "Loopback" -IPAddress 192.168.1.3 -PrefixLength 24
netsh interface ipv4 show address 1
#取消
$IPAddress = "192.168.1.3"
$MatchingInterface = Get-NetIPAddress | Where-Object { $_.IPAddress -eq $IPAddress }
Remove-NetIPAddress -IPAddress $MatchingInterface.IPAddress -InterfaceIndex $MatchingInterface.InterfaceIndex -Confirm:$false
【高、低版本系统均可用cmd配置】
#配置
netsh interface ipv4 add address "Loopback Pseudo-Interface 1" 192.168.1.3 255.255.255.0
#假如IP是61.181.203.164/32
netsh interface ipv4 add address "Loopback Pseudo-Interface 1" 61.181.203.164 255.255.255.255
#取消
netsh interface ipv4 delete address "Loopback Pseudo-Interface 1" 192.168.1.3
netsh interface ipv4 delete address "Loopback Pseudo-Interface 1" 61.181.203.164
我对比了不同版本Windows系统,发现loopback的地址有一定特点,这样来确定
代码语言:javascript复制reg query "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservicesTcpipParametersInterfaces"|findstr 806e6f6e6963
不同版本的Windows系统的loopback注册表地址一般不同,但共性是,注册表地址里都有这个字符串
806e6f6e6963
通用所有Windows系统,以loopback配置61.181.203.164/32 为例
代码语言:powershell复制$loopback=reg query "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservicesTcpipParametersInterfaces"|findstr 806e6f6e6963
reg add $loopback /v DisableDhcpOnConnect /t REG_DWORD /d 1 /f
reg add $loopback /v IPAddress /t REG_MULTI_SZ /d "61.181.203.164 " /f
reg add $loopback /v SubnetMask /t REG_MULTI_SZ /d "255.255.255.255 " /f
netsh interface ipv4 delete address "Loopback Pseudo-Interface 1" 61.181.203.164
netsh interface ipv4 add address "Loopback Pseudo-Interface 1" 61.181.203.164 255.255.255.255
reg query $loopback