6

Helo everyone, i am occasional linux user, but i have a project to do and i need some help with bridging :)
I have tried with google, but didn't solve the problem.

My task is to create network namespace, so it can be used to perform some other tasks from it.

Debian 8.2 is used in VMWare virtual machine on windows 7. I have also tried same things on Raspberry Pi 2, but same problems appear.

First, i have followed tutorial https://lwn.net/Articles/580893/ to create pair of virtual ethernet interfaces. So now i have veth0 in global namespace with ip address 10.1.1.2/24, and veth1 in netns1 namespace with ip address 10.1.1.1/24.

Next, i have followed tutorial http://www.linuxfoundation.org/collaborate/workgroups/networking/bridge to bridge eth0 and veth0, so i can access internet from netns1 namespace.

  • First, i have deleted ip addresses for both eth0 and veth0 interfaces, and set them do DOWN state.

  • New bridge is created (br0) and both interfaces (eth0 and veth0) are added to it.

  • Then both interfaces are set to UP state, and i run "dhclient br0" to assign ip address to br0.

From global namespace now it is possible to run "ping google.com", but from netns1 namespace i get error "Network is unreachable". (I suppose there is problem with routes, i have tried with adding some default routes to netns1 namespace, but no luck. My network knowledge is modest, so i'm asking for help.)

$ 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 master br0 state UP group default qlen 1000
    link/ether 00:0c:29:45:b6:1d brd ff:ff:ff:ff:ff:ff
4: veth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
    link/ether 86:e4:6c:02:b6:79 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::84e4:6cff:fe02:b679/64 scope link 
       valid_lft forever preferred_lft forever
5: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 00:0c:29:45:b6:1d brd ff:ff:ff:ff:ff:ff
    inet 192.168.178.135/24 brd 192.168.178.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe45:b61d/64 scope link 
       valid_lft forever preferred_lft forever

$ route

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.178.2   0.0.0.0         UG    0      0        0 br0
default         192.168.178.2   0.0.0.0         UG    1024   0        0 br0
192.168.178.0   *               255.255.255.0   U     0      0        0 br0

$ ip netns exec netns1 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
3: veth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether ee:b8:f3:47:f7:0c brd ff:ff:ff:ff:ff:ff
    inet 10.1.1.1/24 brd 10.1.1.255 scope global veth1
       valid_lft forever preferred_lft forever
    inet6 fe80::ecb8:f3ff:fe47:f70c/64 scope link 
       valid_lft forever preferred_lft forever

$ ip netns exec netns1 route

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.1.1.0        *               255.255.255.0   U     0      0        0 veth1

$ brctl show

bridge name    bridge id        STP enabled    interfaces
br0        8000.000c2945b61d    no        eth0
                            veth0

Thanks in advance for help :)

chrk
  • 4,037
  • 2
  • 39
  • 47
miki
  • 380
  • 6
  • 15

1 Answers1

8

I have found solution.

Basically, ip forward was missing, along with 2 more steps (i have tried them before, but because of ip forward wasn't enabled, it wasn't working).

Here steps for future readers (after making bridge to work in global namespace ):

  • Assign ip address to veth0 in global namespace (10.1.1.2) because ip address was deleted before creating bridge (in tutorial for bridge they say: "The IP address needs to be set after the bridge has been configured.")
  • Assign default gateway in netns1 namespace to be veth0 in global namespace "ip netns exec netns1 route add default gw 10.1.1.2"
  • Enable ip forwarding "echo 1 > /proc/sys/net/ipv4/ip_forward"
miki
  • 380
  • 6
  • 15