This question is very related. I use the accepted answer to create 10 network namespaces added to my virtualbox network (vboxnet0). However, when trying to ping the new addresses ( from the host machine on which the network namespaces are created I cannot reach them. When trying to ping them from a VM added to that network I can reach them. When pinging the hosts vboxnet0 IP from the host I can reach it. The ping to one of the namespaces however works as soon as I execute the ping command within the corresponding namespace, but only for that IP.

I need to be able to reach the network namespace IPs from the host machine as I want to run scripts on those that need to be fed data. What am I doing wrong?

The script I use for creating the namespaces is added below. (I used to use that script on a VM without problem but due to resource restriction had to move it to my host where the problems now arise)



function create_vlan {
        # echo 1
    ip netns add "ns$1"
        # echo 2
    ip link add link ${networkinterface} "ipvl$1" type ipvlan mode l2
        # echo 3
    ip link set dev "ipvl$1" netns "ns$1"
        # echo 4
    ip netns exec "ns$1" ip link set dev "ipvl$1" up
        # echo 5
    ip netns exec "ns$1" ip link set dev lo up
        # echo 6
    ip netns exec "ns$1" ip -4 addr add dev lo
        # echo 7
    ip netns exec "ns$1" ip -4 addr add $2 dev "ipvl$1"
        # echo 8
    ip netns exec "ns$1" ip -4 route add default via ${ROUTER} dev "ipvl$1"


declare -i metab amount

echo $amount

for i in `seq 30 ${amount}`;
    declare -i metab counter
    counter=`expr $i - 30`
    echo "creating vlan ns${i} with ip $ip"
    create_vlan ${i} ${ip}
    echo "created vlan ns${i} with ip $ip"

It is called with the parameters vboxnet0 and 10

As requested by comment (by anonymized):

ip route
default via 134.A.B.129 dev eno1  proto static  metric 100 
134.A.B.33 via 134.A.B.129 dev eno1  proto dhcp  metric 100 
134.A.B.128/27 dev eno1  proto kernel  scope link  src 134.A.B.132  metric 100 
169.E.F.0/16 dev eno1  scope link  metric 1000 dev vboxnet0  proto kernel  scope link  src
  • What routes have you configured on your host namespace (ip route)?
    – sebasth
    Commented Jan 16, 2018 at 10:30
  • @sebasth I edited my question with the answer to your question
    – Sim
    Commented Jan 16, 2018 at 10:41
  • Please explain exactly what you are trying to do; your setup (with virtualbox) is very different from the setup in the referenced question (lots of namespaces attached to single physical device connected to internet, vs. lots of namespaces attached to non-physical virtualbox device, which does their own internal thing for networking VM guests). What kind of programs run in the VMs? In the netspaces? Should they all see each other under a different IP and Mac? Do you want an external connection? If yes, on which device?
    – dirkt
    Commented Jan 19, 2018 at 17:39
  • @dirkt I have my host and an attached virtual machine connected via vboxnet0. I now want to add an abitrary amount of network namespaces on the host that can communicate with vboxnet0 and enable me to add an arbitrary amount of different IPs. However, I also want to be able to communicate with those IPs from the host and that part is the part that is not working.
    – Sim
    Commented Jan 22, 2018 at 8:58

1 Answer 1


Don't have time to test it now with a virtualbox image, but I suppose the following should work:

My suspicion is that the ipvlan doesn't work well on the virtualbox network adapter, because it's, well, a virtual one.

So do it the old-fashioned way, and use a real bridge, and veth-pairs from the namespaces. So something along the following lines (untested):

ip link add br0 type bridge
ip addr add $addr.250/24 dev br0

Then for every namespace $1 starting from, say, 1:

ip netns add "ns$1"
ip link add "vetha$1" type veth peer name "vethb$1" netns "ns$1"
ip -n "ns$1" link set lo up
ip -n "ns$1" link set "vethb$1" up
ip -n "ns$1" addr add dev lo
ip -n "ns$1" addr add "$addr.$1/24" dev "vethb$1"
ip -n "ns$1" route add default via "$addr.250" dev "vethb$1"
ip link set "vetha$1" master br0
ip link set "vetha$1" up

and finally

ip link set vboxnet0 master br0
ip link set br0 up

Now the bridge with address faces towards to the host, the addresses, etc. get assigned to the namespace, and you must make sure the virtualbox clients get different IPs (or change the addressing scheme). The namespaces have the host as gateway.

If anything doesn't work, you can use ip -n ns0 addr show etc. to check the address assignments, tcpdump -ni vetha0 etc in a different window while pinging to see what works and what doesn't, etc. You can also start an xterm in the namespace to more directly debug stuff.

If the above does work, you can also try a macvlan (very similar to ipvlan), or ipvlan in mode l3 - these are a bit more efficient, if efficiency is need, if they can be made to work with the virtualbox network adapter. Setup for both is very close to your original script.

  • great, I will try it out and report back if it works
    – Sim
    Commented Jan 22, 2018 at 23:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .