2
0
mirror of https://github.com/dadevel/wg-netns synced 2024-10-30 21:20:12 +00:00

update wg-resolve to work together with wg-netns

Resolves #18.
This commit is contained in:
dadevel 2023-05-29 12:46:19 +02:00
parent 008833d7fc
commit da967b34d3
No known key found for this signature in database
GPG Key ID: 1A8A9735430193D5
2 changed files with 9 additions and 2 deletions

View File

@ -1,3 +1,5 @@
# network namespace name
WG_NAMESPACE=netns0
# local wireguard interface name # local wireguard interface name
WG_INTERFACE=wg0 WG_INTERFACE=wg0
# server wireguard public key # server wireguard public key

View File

@ -1,7 +1,12 @@
#!/bin/sh #!/bin/sh
set -eu set -eu
if ! ping -q -c 1 -W "${WG_TIMEOUT:-5}" "$WG_GATEWAY"; then # dependencies: dig, ip, ping and wg
WG_ENDPOINT_DOMAIN="${WG_ENDPOINT%%:*}"
WG_ENDPOINT_PORT="${WG_ENDPOINT##*:}"
if ! ip netns exec "$WG_NAMESPACE" ping -q -c 1 -W "${WG_TIMEOUT:-5}" "$WG_GATEWAY"; then
echo 'probe failed, resolving endpoint' echo 'probe failed, resolving endpoint'
wg set "$WG_INTERFACE" peer "$WG_PEER" endpoint "$WG_ENDPOINT" ip netns exec "$WG_NAMESPACE" wg set "$WG_INTERFACE" peer "$WG_PEER" endpoint "$(dig +short "$WG_ENDPOINT_DOMAIN"):$WG_ENDPOINT_PORT"
fi fi