Switching the egress IP address of a multi-IP application cloud host [Windows System Tutorial]

Published: 2020-06-09

To specify the egress IP, configure as follows:

1. Check the IP configuration

netsh interface ipv4 show ipaddresses level=verbose 

2. Manually delete the IPs that do not need to be set as the egress IP

3. netsh int ipv4 add address "Ethernet 5" 1.2.3.4/24 skipassource=true  Then use this command to re-add the deleted IPs (if there are many IPs, refer to the script handling method in the latter part)


Example:

netsh interface ipv4 show ipaddresses level=verbose shows the following

Address 61.139.126.25 Parameters

———————————————————

Interface Luid : Ethernet 5

Scope ID : 0.0

Valid Lifetime : infinite

Preferred Lifetime : infinite

DAD State : Preferred

Address Type : Manual

Skip as Source : true

Address 61.139.126.42 Parameters

———————————————————

Interface Luid : Ethernet 5

Scope ID : 0.0

Valid Lifetime : infinite

Preferred Lifetime : infinite

DAD State : Preferred

Address Type : Manual

Skip as Source : false

route print

IPv4 Route Table

===========================================================================

Active Routes:

Network Destination Netmask Gateway Interface Metric

0.0.0.0 0.0.0.0 61.139.126.1 61.139.126.42 266


If there are many IPs, refer to the following handling method:

Open the computer's powershell script:

Save the following code as route.ps1, and then it can be executed directly.

$WAN=Get-NetRoute -DestinationPrefix "0.0.0.0/0" | Select-Object -ExpandProperty "ifIndex"
$ips=Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex $WAN | Select-Object -ExpandProperty "IPAddress"
$ipid=0
echo $ips
echo "Please enter the egress IP sequence number (1,2,..):"
$s = Read-Host
foreach($ip in $ips)
{
$ipid=$ipid+1
if($s -eq 0)
{
Set-NetIPAddress -IPAddress $ip -SkipAsSource $false
}elseif($ipid -eq $s)
{
Set-NetIPAddress -IPAddress $ip -SkipAsSource $false
} else {
Set-NetIPAddress -IPAddress $ip -SkipAsSource $true
}
}
get-netipaddress -AddressFamily IPv4 -InterfaceIndex $WAN| select ipaddress, skipassource

Then open PowerShell and execute it. Regarding the sequence number selection, the IP addresses are listed here. If you want to set 60.247.175.120 as the egress IP, subtract the last octet of the IP to be set from the last octet of the largest IP in the list, 126, and the resulting number is the sequence number.

image.png