wireguard-setup/scripts/inner.sh

43 lines
1.1 KiB
Bash

#!/usr/bin/env bash
ip link add veth-inner type veth peer name veth-outer
ip link set dev veth-outer netns default
ip link set dev veth-inner master mynet0
ip link set dev veth-inner up
ip link set dev mynet0 up
ip link set dev veth-inner up
wg setconf vpn /snacks/wireguard/wg.conf
ip link set dev vpn up
ip addr flush dev vpn
ip route flush dev vpn
echo "-- <start> inner.sh --"
echo "VPN_IPV4_ADDRESS=${VPN_IPV4_ADDRESS}"
echo "VPN_IPV6_ADDRESS=${VPN_IPV6_ADDRESS}"
echo "OUTER_ROUTE_V4=${OUTER_ROUTE_V4}"
echo "OUTER_GATEWAY_V4=${OUTER_GATEWAY_V4}"
echo "OUTER_ROUTE_V6=${OUTER_ROUTE_V6}"
echo "OUTER_GATEWAY_V6=${OUTER_GATEWAY_V6}"
echo "-- <end> inner.sh --"
ip addr add ${VPN_IPV4_ADDRESS} dev vpn
ip addr add ${VPN_IPV6_ADDRESS} dev vpn
if [ -n "${OUTER_ROUTE_V4}" && -n "${OUTER_GATEWAY_V4}" ]
then
ip -4 route add "${OUTER_ROUTE_V4}" via "${OUTER_GATEWAY_V4}"
fi
if [ -n "${OUTER_ROUTE_V6}" && -n "${OUTER_GATEWAY_V6}" ]
then
ip -6 route add "${OUTER_ROUTE_V6}" via "${OUTER_GATEWAY_V6}"
fi
ip -4 route add default dev vpn
ip -6 route add default dev vpn