Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow env variable #203

Merged
merged 3 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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