Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example Script for using network namespaces
set -e
# Network namespace example
# Inspired by
ip netns add $NNS
ip link add $DEV_OUTSIDE type veth peer name $DEV_INSIDE
ip link set $DEV_INSIDE netns $NNS
ip netns exec $NNS ip link set dev $DEV_INSIDE up
ip netns exec $NNS ip addr add $IP_INSIDE dev $DEV_INSIDE
ip link set dev $DEV_OUTSIDE up
ip add add $IP_OUTSIDE dev $DEV_OUTSIDE
ip netns exec $NNS /usr/sbin/sshd -p 22
echo "you now can connect to fec0::1 via ssh"

This comment has been minimized.

Copy link
Owner Author

commented Jul 17, 2018

Interesting use cases:

  • start a vpn inside that namespace and you have isolated your host.
  • use it for services that should only be available locally
  • use it for routing tests
  • isolate applications i.e. having a local DNS resolver and a DNS server running locally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.