Last active
August 29, 2015 13:56
-
-
Save mrhjkim/9046510 to your computer and use it in GitHub Desktop.
network name space in linux
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
network name space in linux. | |
create two network name spaces each having ip of 10.0.0.1 and 10.0.0.2 and ping test | |
configuration | |
host:s1-eth <-----> ns1:h1-eth | |
host:s2-eth <-----> ns2:h2-eth | |
1. create network name space | |
ip netns add ns1 | |
ip netns add ns2 | |
2. make virtual network device pair | |
ip link add s1-eth type veth peer name h1-eth | |
ip link add s2-eth type veth peer name h2-eth | |
3. associate virtual device with name space | |
ip link set h1-eth netns ns1 | |
ip link set h2-eth netns ns2 | |
4. set up lo(local loop) in name space | |
ip netns exec ns1 ifconfig lo up | |
ip netns exec ns2 ifconfig lo up | |
5. assign ip in name space | |
ip netns exec ns1 ifconfig h1-eth 10.0.0.1/24 up | |
ip netns exec ns2 ifconfig h2-eth 10.0.0.2/24 up | |
6. make virtual interface up in host | |
ifconfig s1-eth up | |
ifconfig s2-eth up | |
7. make bridge device and associate virtual device with bridge device | |
brctl addbr br0 | |
brctl addif br0 s1-eth | |
brctl addif br0 s2-eth | |
8. make bridge device up | |
ip link set br0 up | |
9. test | |
ip netns exec ns1 ping 10.0.0.2 | |
ip netns exec ns1 ping 10.0.0.1 | |
ip netns exec ns2 ping 10.0.0.1 | |
ip netns show | |
ip netns list | |
10. clean up | |
ip netns delete ns1 | |
ip netns delete ns2 | |
brctl delbr br0 | |
ifconfig br0 down | |
brctl delbr br0 | |
brctl show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment