wireguard-setup/scripts/inner.sh

43 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2021-02-25 12:17:46 +00:00
#!/usr/bin/env bash
2021-02-25 10:19:46 +00:00
ip link add veth-inner type veth peer name veth-outer
2021-02-25 12:17:46 +00:00
ip link set dev veth-outer netns default
2021-02-25 10:19:46 +00:00
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
2022-04-03 13:36:29 +00:00
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 --"
2021-02-25 12:17:46 +00:00
2021-02-25 10:19:46 +00:00
ip addr add ${VPN_IPV4_ADDRESS} dev vpn
ip addr add ${VPN_IPV6_ADDRESS} dev vpn
2021-02-25 12:17:46 +00:00
2022-04-03 13:36:29 +00:00
if [ -n "${OUTER_ROUTE_V4}" && -n "${OUTER_GATEWAY_V4}" ]
2021-10-13 11:58:01 +00:00
then
2021-10-13 12:09:50 +00:00
ip -4 route add "${OUTER_ROUTE_V4}" via "${OUTER_GATEWAY_V4}"
fi
2022-04-03 13:36:29 +00:00
if [ -n "${OUTER_ROUTE_V6}" && -n "${OUTER_GATEWAY_V6}" ]
2021-10-13 12:09:50 +00:00
then
ip -6 route add "${OUTER_ROUTE_V6}" via "${OUTER_GATEWAY_V6}"
2021-10-13 11:58:01 +00:00
fi
2021-02-25 10:19:46 +00:00
ip -4 route add default dev vpn
ip -6 route add default dev vpn