Created
November 6, 2019 15:53
-
-
Save ninlith/465834a440ce1d6bbfa482b09f497dee to your computer and use it in GitHub Desktop.
Transfers OpenVPN tunnel interface to a network namespace as its only non-localhost interface.
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
#!/usr/bin/env bash | |
# Transfers VPN tunnel interface to a network namespace as its only | |
# non-localhost interface. | |
# | |
# Based on <https://github.com/slingamn/namespaced-openvpn>. | |
sudo ip netns add protected | |
sudo ip netns exec protected ip link set lo up | |
sudo openvpn "$@" --ifconfig-noexec --route-noexec --script-security 2\ | |
--route-up '/bin/sh -c "sudo ip link set $dev netns protected\ | |
sudo ip netns exec protected sh <<EOF\ | |
ip link set $dev up\ | |
ip addr add $ifconfig_local peer $route_vpn_gateway/32 dev $dev\ | |
ip route add default dev $dev\ | |
exit\ | |
EOF"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment