Custom Search

Monday, July 28, 2014

Howto connect two network namespaces using veth pairs

1)
Add two namespaces "ns1" and "ns2"
#sudo ip netns add ns1
#sudo ip netns add ns2

2)
List all namespaces
#sudo ip netns list

3)
List all interfaces in the global namespace
#ifconfig  -a
OR
#ifconfig -a | less

4)
Create veth interface pairs "tap1" and "tap2" in the global namespace
#sudo ip link add tap1 type veth peer name tap2

5)
List all interfaces in the global namespace
#ifconfig  -a
OR
#ifconfig -a | less

* At this point the interfaces "tap1" and "tap2" doesn't have IP associated with it.

6)
Move "tap1" and "tap2" interfaces from global namespace to the "ns1"and "ns2" namespace.

* Move "tap1" interface to "ns1" namespace
#sudo ip link set tap1 netns ns1

* Move "tap2" interface to "ns2" namespace
#sudo ip link set tap2 netns ns2

* At this point run "#ifconfig -a" in global namespace an you would not able to see the "tap1" and "tap2" interfaces there.

7)
Goto namespace "ns1" and "ns2" and run "#ifconfig -a" to see the interface "tap1" and "tap2"
#sudo ip netns exec ns1 ifconfig -a
#sudo ip netns exec ns2 ifconfig -a

8)
Assign IP addess to "tap1" and "tap2"
#sudo ip netns exec ns1 ip addr add 10.1.1.4/16 dev tap1
#sudo ip netns exec ns2 ip addr add 10.1.1.5/16 dev tap2

9)
Bring up the link/interface "tap1" and "tap2"
#sudo ip netns exec ns1 ip link set tap1 up
#sudo ip netns exec ns2 ip link set tap2 up

10)
Check the IP address of the interface "tap1" and "tap2"
#sudo ip netns exec ns1 ifconfig -a
#sudo ip netns exec ns2 ifconfig -a

11)
Ping from ns1 to ns2
#sudo ip netns exec ns1 ping 10.1.1.5

12)
Ping from ns2 to ns1
#sudo ip netns exec ns2 ping 10.1.1.4

13)
http://www.opencloudblog.com/?p=66




No comments:

Post a Comment