Namespaces is a Linux concept used to isolate processes and programs from each other on a machine. Namespaces have their own network stack, addresses, routing tables,...

Creating namespaces:

We can create namespaces using the below command:


We can check if the namespaces were created using the below command:


To display the network interfaces in the namespace_1 for example, we use:


The "ip link" command is executed inside the "namespace_1".

Connecting two namespaces:

In order for the namespace_1 and namespace_2 to communicate, we create a connection (comparable to a physical network cable) and we connect one end to namespace_1 and the other end to namespace_2.


Creation of the "veth" virtual cables:


Using the above command we create a virtual cable with two ends:

We, then connect end_1 to namespace_1


And we
 connect end_2 to namespace_2:


We give each "virtual cable" end an IP address:


We, then enable the interfaces:


To check the connection, we try to ping namespace_2 from namespace_1:


Remark:

To delete a cable we use the below command (deleting one end of the connection, deletes also the other end):


Using the Linux bridge:


When we want to connect more than two namespaces, we would need a bridge. Linux offers us a virtual bridge. 
We create a virtual bridge "bridge_1" using:


We check if the bridge was created using the below command. On the host "bridge_1" appears as an interface:


We activate the "bridge_1" interface:


Creating the namespaces links to the bridge:


We attach the link namespace_1_end_1 to namespace_1


We, then attach bridge_end_1 to the Linux bridge bridge_1:


We do the same for namespace_2:


We, then attach bridge_end_2 to the Linux bridge bridge_1:

 
We assign IP addresses to the links:


Finally, we enable the links on the namespace:


Brando Sabatini and Ikbal C ©. Powered by Blogger.