0

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
3
  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

  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Mark Henderson Jun 24 '15 at 4:26
  • @MarkHenderson my bad, edited, will take more care next time. cheers. – guoger Jun 24 '15 at 5:35
  • No worries, that's a much better answer now :) – Mark Henderson Jun 24 '15 at 5:36
1

Same as you, I struggled with veth, and failed to make it work.

Then I found this, which says:

Before MACVLAN, if you wanted to connect to physical network from a VM or namespace, you would have needed to create TAP/VETH devices and attach one side to a bridge and attach a physical interface to the bridge on the host at the same time, as shown below.

Now, with MACVLAN, you can bind a physical interface that is associated with a MACVLAN directly to namespaces, without the need for a bridge.

So I tried this:

$ sudo ip netns add ns0
$ sudo ip netns exec ns0 ip link set lo up
$ sudo ip link add macvlan0 link eth0 type macvlan mode bridge
$ sudo ip link set macvlan0 netns ns0
$ sudo ip netns exec ns0 ip link set macvlan0 up
$ sudo ip netns exec ns0 ip addr add 172.29.6.123/21 dev macvlan0
$ sudo ip netns exec ns0 ping 172.29.0.1
PING 172.29.0.1 (172.29.0.1) 56(84) bytes of data.
64 bytes from 172.29.0.1: icmp_seq=1 ttl=64 time=0.360 ms
64 bytes from 172.29.0.1: icmp_seq=2 ttl=64 time=0.412 ms

It is working!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.