diff --git a/README.md b/README.md index f17e83f..9c57278 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,8 @@ wsl.exe -d wsl-vpnkit --cd /app wsl-vpnkit `wsl-vpnkit` uses `/mnt/wsl/resolv.conf` to get the WSL 2 gateway IP. If modifying `/etc/resolv.conf` to set a custom DNS configuration, set [`generateResolvConf=false` in `wsl.conf`](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#network-settings). +On older WSL versions where `/mnt/wsl/resolv.conf` is not available, `wsl-vpnkit` will fallback to using `/etc/resolv.conf`. When setup as a standalone script and using a custom DNS configuration for the distro, the `WSL2_GATEWAY_IP` environment variable should be set for `wsl-vpnkit` to use. + #### wsl-gvproxy.exe is not executable due to WSL interop settings or Windows permissions `wsl-vpnkit` requires that the WSL 2 distro be able to run Windows executables. This [`interop` setting](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#interop-settings) is enabled by default in WSL 2 and in the `wsl-vpnkit` distro. diff --git a/wsl-vpnkit b/wsl-vpnkit index 0de675c..e610d7c 100755 --- a/wsl-vpnkit +++ b/wsl-vpnkit @@ -3,10 +3,10 @@ set -x # hardcoded in gvisor-tap-vsock -VPNKIT_GATEWAY_IP="192.168.127.1" -VPNKIT_HOST_IP="192.168.127.254" -VPNKIT_LOCAL_IP="192.168.127.2" -TAP_MAC_ADDR="5a:94:ef:e4:0c:ee" +VPNKIT_GATEWAY_IP=${VPNKIT_GATEWAY_IP:-192.168.127.1} +VPNKIT_HOST_IP=${VPNKIT_HOST_IP:-192.168.127.254} +VPNKIT_LOCAL_IP=${VPNKIT_LOCAL_IP:-192.168.127.2} +TAP_MAC_ADDR=${TAP_MAC_ADDR:-5a:94:ef:e4:0c:ee} # overrideable with env VMEXEC_PATH=${VMEXEC_PATH:-/app/wsl-vm} @@ -19,9 +19,14 @@ DEBUG=${DEBUG:-0} set +x # WSL2 default values -WSL2_TAP_NAME="eth0" -WSL2_RESOLVCONF="/mnt/wsl/resolv.conf" -WSL2_GATEWAY_IP="$(cat $WSL2_RESOLVCONF | awk '/^nameserver/ {print $2}')" +WSL2_TAP_NAME=${WSL2_TAP_NAME:-eth0} +WSL2_RESOLVCONF_DEFAULT="/mnt/wsl/resolv.conf" +if [ ! -f "$WSL2_RESOLVCONF_DEFAULT" ]; then + WSL2_RESOLVCONF_DEFAULT="/etc/resolv.conf" +fi +WSL2_RESOLVCONF=${WSL2_RESOLVCONF:-$WSL2_RESOLVCONF_DEFAULT} +WSL2_GATEWAY_IP_FROM_RESOLVCONF="$(cat $WSL2_RESOLVCONF | awk '/^nameserver/ {print $2}')" +WSL2_GATEWAY_IP=${WSL2_GATEWAY_IP:-$WSL2_GATEWAY_IP_FROM_RESOLVCONF} set -x @@ -142,7 +147,6 @@ fi cat $WSL2_RESOLVCONF | grep "automatically generated by WSL" >/dev/null if [ $? -eq 1 ]; then echo "resolv.conf has been modified without setting generateResolvConf" - exit 1 fi $GVPROXY_PATH -help 2>/dev/null if [ $? -eq 1 ]; then