Created
May 16, 2024 22:43
-
-
Save twilligon/4a6dca48422acc8f8c623cbd0921a3f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -eu | |
| NETNS="$(printf '%s' "$1" | sed -n 's#.*/\([^.]*\)\..*#\1#p')" | |
| mkdir -p "/etc/netns/${NETNS}" | |
| sed -nr 's/^DNS = (.*)/\1/p' "$1" | tr ',' '\n' | sed 's/^/nameserver /' > "/etc/netns/${NETNS}/resolv.conf" | |
| ip netns del "${NETNS}" 2>/dev/null || : | |
| ip netns add "${NETNS}" | |
| ip link add "${NETNS}" type wireguard | |
| sed 's/^Address =/#Address =/g;s/^DNS =/#DNS =/' "$1" | wg setconf "${NETNS}" /dev/stdin | |
| ip link set "${NETNS}" netns "${NETNS}" | |
| sed -nr 's/^Address = (.*)/\1/p' "$1" | tr ',' '\n' | sed "s/^/ip -n ${NETNS} addr add /;s/\$/ dev ${NETNS}/" | sh | |
| ip -n "${NETNS}" link set "${NETNS}" up | |
| ip -n "${NETNS}" route add default dev "${NETNS}" | |
| ip -n "${NETNS}" link set lo up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
License: CC0-1.0