Skip to content

Instantly share code, notes, and snippets.

@zeha
Last active December 15, 2015 08:49
Show Gist options
  • Save zeha/5233288 to your computer and use it in GitHub Desktop.
Save zeha/5233288 to your computer and use it in GitHub Desktop.
quick howto netns
assumption: your machine has eth0 bridged to br0 already
(everything as root)
create a new netns:
-------------------
ip netns add foo
ip netns exec foo bash
get pid of that bash:
echo $$
17484
(don't terminate that bash, it holds open your netns.)
create a veth device pair:
--------------------------
foolink will be the host side, foointernal will be the netns side:
from a "host" shell:
ip link add name foolink type veth peer name foointernal
link the netns/veth:
--------------------
ip link set foointernal netns 14784 # pid of the bash from above
ip link set foolink up
brctl addif br0 foolink
if you have an ipv6 network, your foointernal device should already have an ipv6 address by now.
use ip addr add to give it an ipv4 as well (or try dhclient).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment