Difference between revisions of "Wsl2 vpn fix route"

From UVOO Tech Wiki
Jump to navigation Jump to search
Line 23: Line 23:
 
Get-NetAdapter | Where-Object { $_.InterfaceDescription -like "PANGP*" } | Set-NetIPInterface -InterfaceMetric 4000
 
Get-NetAdapter | Where-Object { $_.InterfaceDescription -like "PANGP*" } | Set-NetIPInterface -InterfaceMetric 4000
 
# Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 4000
 
# Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 4000
 +
```
 +
 +
 +
# Messy Notes
 +
```
 +
$interface = Get-NetIPConfiguration | Where-Object { $_.InterfaceAlias -eq "vEthernet (WSL)" }
 +
$prefixLength = $interface.IPv4Address | Select-Object -ExpandProperty PrefixLength
 +
$binaryMask = ('1' * $prefixLength).PadRight(32, '0'); $subnetMask = [convert]::ToInt32($binaryMask.Substring(0, 8), 2).ToString() + '.' + [convert]::ToInt32($binaryMask.Substring(8, 8), 2).ToString() + '.' + [convert]::ToInt32($binaryMask.Substring(16, 8), 2).ToString() + '.' + [convert]::ToInt32($binaryMask.Substring(24, 8), 2).ToString(); Write-Output $subnetMask
 +
 +
route add $interface.IPv4Address.IPAddress MASK $subnetMask 10.x.x.1
 
```
 
```

Revision as of 23:21, 12 August 2024

Get-NetIPInterface -InterfaceAlias "vEthernet (WSL)" | Set-NetIPInterface -InterfaceMetric 1
Get-NetAdapter | Where-Object { $_.InterfaceDescription -like "PANGP*" } | Set-NetIPInterface -InterfaceMetric 4000
# Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 4000

Set routes to default gateway

route add 0.0.0.0 MASK 0.0.0.0 10.x.x.1
route add 172.24.192.0 MASK 255.255.240.0 10.x.x.1
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
    # Re-launch the script with elevated privileges
    $arguments = "& '" + $myInvocation.MyCommand.Definition + "'"
    Start-Process powershell -Verb runAs -ArgumentList $arguments
    exit
}

Get-NetIPInterface -InterfaceAlias "vEthernet (WSL)" | Set-NetIPInterface -InterfaceMetric 1
Get-NetAdapter | Where-Object { $_.InterfaceDescription -like "PANGP*" } | Set-NetIPInterface -InterfaceMetric 4000
# Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 4000

Messy Notes

$interface = Get-NetIPConfiguration | Where-Object { $_.InterfaceAlias -eq "vEthernet (WSL)" }
$prefixLength = $interface.IPv4Address | Select-Object -ExpandProperty PrefixLength
$binaryMask = ('1' * $prefixLength).PadRight(32, '0'); $subnetMask = [convert]::ToInt32($binaryMask.Substring(0, 8), 2).ToString() + '.' + [convert]::ToInt32($binaryMask.Substring(8, 8), 2).ToString() + '.' + [convert]::ToInt32($binaryMask.Substring(16, 8), 2).ToString() + '.' + [convert]::ToInt32($binaryMask.Substring(24, 8), 2).ToString(); Write-Output $subnetMask

route add $interface.IPv4Address.IPAddress MASK $subnetMask 10.x.x.1