How to create a network namespace in Linux?

How to create a network namespace in Linux?

For example, let’s say you wanted to create a namespace called “blue”. You’d use this command: To verify that the network namespace has been created, use this command: You should see your network namespace listed there, ready for you to use.

How to connect a network namespace to a physical network?

To connect a network namespace to the physical network, just use a bridge. In my case, I used an Open vSwitch (OVS) bridge, but a standard Linux bridge would work as well. Place one or more physical interfaces as well as one of the veth interfaces in the bridge, and—bam!—there you go.

Can a network namespace be used for Nating?

However, NATing becomes a problem because the host won’t know which VM to return the traffic to. To solve this problem, we can use network namespaces and some veth (virtual Ethernet) devices to connect up each private network we want to NAT.

How to add a device to a namespace?

The IP will be on the other end in the namespace. Next we want to add the peer1-gw1 device to the namespace, give it an IP on the routable network, set the default gateway and bring the device up. Note that if you use DHCP you can do that, here I’m just setting an IP statically to 192.168.0.100 and gateway of 192.168.0.1.

How to connect different namespaces to different VLANs?

Place one or more physical interfaces as well as one of the veth interfaces in the bridge, and—bam!—there you go. Naturally, if you had different namespaces, you’d probably want/need to connect them to different physical networks or different VLANs on the physical network.

Why are there so many namespaces in OpenStack?

While it might seem a bit esoteric right now, trust me that there is a reason why I’m introducing you to network namespaces—if you, like me, are on a journey to better understand OpenStack, you’ll almost certainly run into network namespaces again. So what are network namespaces?