diff options
-rw-r--r-- | wsl/README.md | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/wsl/README.md b/wsl/README.md index e639153..c957f6b 100644 --- a/wsl/README.md +++ b/wsl/README.md @@ -1,8 +1,30 @@ ## Force DNS Usage inside VPN -### SystemD +### Bash script + +```bash +$ cat /bin/vpn-dns +#!/bin/bash + +echo "Getting current DNS servers, this takes a couple of seconds" + +/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command ' +$ErrorActionPreference="SilentlyContinue" +Get-NetAdapter -InterfaceDescription "WireGuard Tunnel*" | Get-DnsClientServerAddress | Select -ExpandProperty ServerAddresses +Get-NetAdapter | ?{-not ($_.InterfaceDescription -like "WireGuard Tunnel*") } | Get-DnsClientServerAddress | Select -ExpandProperty ServerAddresses +' | \ + awk 'BEGIN { print "# Generated by vpn fix func on", strftime("%c"); print } { print "nameserver", $1 }' | \ + tr -d '\r' > /etc/resolv.conf +clear +``` + +### Configure Init + +#### SystemD + +Save file into /etc/systemd/system/vpn-dns.service with 755 permissions + ```bash -$ cat /etc/systemd/system/vpn-dns.service [Unit] Description=VPN DNS Configuration @@ -15,7 +37,9 @@ Environment=TERM=xterm WantedBy=multi-user.target ``` -### OpenRC +#### OpenRC + +Save file into /etc/init.d/vpn-dn swith 755 permissions ```bash #!/sbin/openrc-run @@ -48,21 +72,6 @@ stop() { } ``` -```bash -$ cat /bin/vpn-dns -#!/bin/bash - -echo "Getting current DNS servers, this takes a couple of seconds" - -/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command ' -$ErrorActionPreference="SilentlyContinue" -Get-NetAdapter -InterfaceDescription "WireGuard Tunnel*" | Get-DnsClientServerAddress | Select -ExpandProperty ServerAddresses -Get-NetAdapter | ?{-not ($_.InterfaceDescription -like "WireGuard Tunnel*") } | Get-DnsClientServerAddress | Select -ExpandProperty ServerAddresses -' | \ - awk 'BEGIN { print "# Generated by vpn fix func on", strftime("%c"); print } { print "nameserver", $1 }' | \ - tr -d '\r' > /etc/resolv.conf -clear -``` ### Show Networks c/> Get-NetAdapter |