Skip to content

Commit

Permalink
allow env variable (#203)
Browse files Browse the repository at this point in the history
* allow env variable

* look for /etc if /mnt/wsl is not available

* update readme for the new behavior
  • Loading branch information
sakai135 authored Apr 4, 2023
1 parent f1826fa commit dcc6b97
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 12 additions & 8 deletions wsl-vpnkit
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dcc6b97

Please sign in to comment.