add script that prepares system for use of our wrapper script
[0tDNS.git] / netns-script
blob36cbda999ff5e43ea27ebb5362472e7278f417cc
1 #!/bin/sh
3 # adapted from
4 # https://unix.stackexchange.com/questions/149293/feed-all-traffic-through-openvpn-for-a-specific-network-namespace-only
6 case $script_type in
7 up)
8 ip netns add 0tdns
9 ip netns exec 0tdns ip link set dev lo up
10 ip link set dev "$1" up netns 0tdns mtu "$2"
11 ip netns exec 0tdns ip addr add dev "$1" \
12 "$4/${ifconfig_netmask:-30}" \
13 ${ifconfig_broadcast:+broadcast "$ifconfig_broadcast"}
14 if [ -n "$ifconfig_ipv6_local" ]; then
15 ip netns exec 0tdns ip addr add dev "$1" \
16 "$ifconfig_ipv6_local"/112
19 route-up)
20 ip netns exec 0tdns ip route add default via "$ifconfig_remote"
22 if [ -n "$ifconfig_ipv6_remote" ]; then
23 ip netns exec 0tdns ip route add default via \
24 "$ifconfig_ipv6_remote"
27 # notify our sh process, that openvpn finished initializing
28 kill -usr1 `cat /var/lib/0tdns/shell_pid`
30 # we no longer need this connection
31 #kill $OPENVPN_PID
34 down)
35 ip netns delete 0tdns
37 esac