Linux Namespace – Routing Instance

In Linux, in the past I was using iproute2 and multiple routing tables to do some more advance stuff but when I became aware of Namespace, things really changed for me. Namespaces in Linux seem to be similar to logical systems in Junos. It seems to be a bit more than a routing instance in my opinion. I believe this much of introduction is sufficient. Now I would like to show several commands by which we can create a new routing instance inside a Linux box. To this new routing instance we will also assign a VLAN interface.

I have a linux box named vHost2. It has 2 physical ethernet interfaces as you can see. (Actually more but I am hiding some to make the output more brief) eth1 is connected to a trunk port on the switch side so that I can create vlan interfaces on this physical interface.

First create the vlan interface.

Yes now we have vlan971 interface created. If we speak in Junos terms, we created the interface on the master routing instance. Now we will create a new name space named BRANCHD

Great! we have the first routing instance on the system. We also checked the interface list on this name space and as you can see there is only loopback interface. It is a new instance created with no other interfaces bound to it. Now we will assing this vlan971 interface which is tied to the physical interface eth1 to this name space.

See? now we have a new interface on this instance. Now it is time to assign and IP and default route

Now our routing instance device is ready! For any changes, you can use the “ip netns exec” command. It gives you enourmous flexibility actually. For example in addition to routing you have also a separate netfilter i.e you can use separate iptables rules for your new instance. In the past I was firing up a new virtual machine to do some operations but after name space, I can simulate dozens of nodes with different services in a couple of minutes with just a few linux commands. Why I am so enthusiastic about this? I think I consider this like a swiss knife for networking. It made a lot of time consuming stuff so easier now. If you do any fancy stuff with namespaces, please do share here.

One thought on “Linux Namespace – Routing Instance

You have a feedback?