Ubuntu – How to connect custom network namespace to root network namespace

network-namespacenetworkingUbuntu

I would like to connect the root network namespace to my custom network namespace in my Ubuntu box. Here is my network diagram:

enter image description here

Basically my custom network namespace is the one who control the vm network (such as assigning IP, etc).

I would like to see if I can set up a veth pair such that other Host which is the same subnet of eth1 (10.0.1.0/24) can access to it.

I was trying to do ip link set command but no luck with that as the interface (qg-1ee92648-d5) that I want to connect to is in the custom network namespace

Here is my Host network configuration:

vagrant@ubuntu:~$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode   DEFAULT group default 
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 00:0c:29:cd:e0:99 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 00:0c:29:cd:e0:a3 brd ff:ff:ff:ff:ff:ff

vagrant@ubuntu:~$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:cd:e0:99 brd ff:ff:ff:ff:ff:ff
    inet 192.168.106.129/24 brd 192.168.106.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fecd:e099/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:cd:e0:a3 brd ff:ff:ff:ff:ff:ff
    inet 10.0.1.10/24 brd 10.0.1.255 scope global eth1
       valid_lft forever preferred_lft forever

My custom namespace configuration:

vagrant@ubuntu:~$ sudo ip netns exec  qrouter-7646dc10-7727-41b4-addd-8d08888cd764 ip
 link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: qr-d174c5e5-c7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether fa:16:3e:b3:cc:c2 brd ff:ff:ff:ff:ff:ff
3: qg-1ee92648-d5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether fa:16:3e:f2:1d:2f brd ff:ff:ff:ff:ff:ff


vagrant@ubuntu:~$ sudo ip netns exec  qrouter-7646dc10-7727-41b4-addd-8d08888cd764 ip
 addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: qr-d174c5e5-c7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether fa:16:3e:b3:cc:c2 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.1/24 brd 10.0.0.255 scope global qr-d174c5e5-c7
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:feb3:ccc2/64 scope link 
       valid_lft forever preferred_lft forever
3: qg-1ee92648-d5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether fa:16:3e:f2:1d:2f brd ff:ff:ff:ff:ff:ff
    inet 10.0.1.102/24 brd 10.0.1.255 scope global qg-1ee92648-d5
       valid_lft forever preferred_lft forever
    inet 10.0.1.101/32 brd 10.0.1.101 scope global qg-1ee92648-d5
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fef2:1d2f/64 scope link 
       valid_lft forever preferred_lft forever

Best Answer

  1. Use Linux Bridge and inter-connect namespaces via veth pair.
  2. Use OpenVSwitch and its internal ports

Refer to this step-by-step guide: http://www.opencloudblog.com/?p=66

For example (quote from above post) if you want to connect two namespaces with one linux bridge and two veth pairs, in order to realize a topology in this graph: enter image description here

# add the namespaces
ip netns add ns1
ip netns add ns2
# create the switch
BRIDGE=br-test
brctl addbr $BRIDGE
brctl stp   $BRIDGE off
ip link set dev $BRIDGE up
#
#### PORT 1
# create a port pair
ip link add tap1 type veth peer name br-tap1
# attach one side to linuxbridge
brctl addif br-test br-tap1 
# attach the other side to namespace
ip link set tap1 netns ns1
# set the ports to up
ip netns exec ns1 ip link set dev tap1 up
ip link set dev br-tap1 up
#
#### PORT 2
# create a port pair
ip link add tap2 type veth peer name br-tap2
# attach one side to linuxbridge
brctl addif br-test br-tap2
# attach the other side to namespace
ip link set tap2 netns ns2
# set the ports to up
ip netns exec ns2 ip link set dev tap2 up
ip link set dev br-tap2 up
#

Please refer to original post for more details on OVS. Cheers