You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wg-netns/extras/wg-resolve/wg-resolve.sh

13 lines
442 B
Bash

#!/bin/sh
set -eu
# dependencies: cut, getent, 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'
ip netns exec "$WG_NAMESPACE" wg set "$WG_INTERFACE" peer "$WG_PEER" endpoint "$(getent hosts -- "$WG_ENDPOINT_DOMAIN" | cut -d ' ' -f 1):$WG_ENDPOINT_PORT"
fi