Skip to content

Instantly share code, notes, and snippets.

@DistantThunder
Created November 3, 2016 14:01
Show Gist options
  • Save DistantThunder/8f0fae1d03f141f5c4a9bd1ec1dbf6b3 to your computer and use it in GitHub Desktop.
Save DistantThunder/8f0fae1d03f141f5c4a9bd1ec1dbf6b3 to your computer and use it in GitHub Desktop.
Little script originating from "http://unix.stackexchange.com/questions/149293/feed-all-traffic-through-openvpn-for-a-specific-network-namespace-only/196116#196116" creating network namespaces with the OpenVPN connection. IPv6 section is commented out, you can re-enable it yourself.
1 #!/bin/sh
2
3 set -x
4 case $script_type in
5 up)
6 ip netns add vpn
7 ip netns exec vpn ip link set dev lo up
8 mkdir -p /etc/netns/vpn
9 ip link set dev "$1" up netns vpn mtu "$2"
10 ip netns exec vpn ip addr add dev "$1" \
11 "$4/${ifconfig_netmask:-30}" \
12 ${ifconfig_broadcast:+broadcast "$ifconfig_broadcast"}
13 #test -n "$ifconfig_ipv6_local" && \
14 #ip netns exec vpn ip addr add dev "$1" \
15 # "$ifconfig_ipv6_local"/112
16 ;;
17 route-up)
18 ip netns exec vpn ip route add default via "$route_vpn_gateway"
19 #test -n "$ifconfig_ipv6_remote" && \
20 #ip netns exec vpn ip route add default via \
21 #"$ifconfig_ipv6_remote"
22 ;;
23 down)
24 ip netns delete vpn
25 ;;
26 esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment