Created
March 2, 2018 21:41
-
-
Save DeadSix27/9c1a896b9f12c4d99e43df2932e2715a to your computer and use it in GitHub Desktop.
network namespace example
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
| # 1_create.sh | |
| # Creates the namespaces and routes for the vpn namespace. | |
| ################ | |
| #!/usr/bin/env bash | |
| ip netns add vpn | |
| ip netns exec vpn ip addr add 127.0.0.1/8 dev lo | |
| ip netns exec vpn ip link set lo up | |
| ip link add vpn0 type veth peer name vpn1 | |
| ip link set vpn0 up | |
| ip link set vpn1 netns vpn up | |
| ip addr add 10.200.200.1/24 dev vpn0 | |
| ip netns exec vpn ip addr add 10.200.200.2/24 dev vpn1 | |
| ip netns exec vpn ip route add default via 10.200.200.1 dev vpn1 | |
| iptables -A INPUT \! -i vpn0 -s 10.200.200.0/24 -j DROP | |
| iptables -t nat -A POSTROUTING -s 10.200.200.0/24 -o en+ -j MASQUERADE | |
| sysctl -q net.ipv4.ip_forward=1 | |
| ## 2_create.sh ## Creates a screen with the ovpn client on the namespace | |
| ################ | |
| #!/usr/bin/env bash | |
| ip netns exec azirevpn sudo openvpn --config VPN.ovpn | |
| screen -dmS "ovpn" | |
| screen -S "ovpn" -X stuff "sudo ip netns exec vpn sudo openvpn --config VPN.ovpn^M" | |
| screen -r "ovpn" | |
| ## Done | |
| ################ | |
| Now I could open more screens on the namespace if needed for various programs. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment