{"id":1,"date":"2024-11-14T18:16:34","date_gmt":"2024-11-14T18:16:34","guid":{"rendered":"http:\/\/aiinfrahub.com\/?p=1"},"modified":"2025-03-02T10:06:10","modified_gmt":"2025-03-02T10:06:10","slug":"linux-network-namespace","status":"publish","type":"post","link":"https:\/\/aiinfrahub.com\/about-us\/linux-network-namespace\/","title":{"rendered":"Linux Network Namespace"},"content":{"rendered":"\n<p>Linux Namespaces are operating system constructs which provides a containers the required isolation so that resources of one container shall not interfere with others containers and the host. In other words, we make sure that a process running in one container can\u2019t easily interfere with the operation of another container or the underlying host?<\/p>\n\n\n\n<p>Linux support following namespaces:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"692\" height=\"238\" src=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-1.png\" alt=\"\" class=\"wp-image-32\" srcset=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-1.png 692w, https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-1-300x103.png 300w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/figure>\n\n\n\n<p>Command to list namespaces:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"377\" height=\"307\" src=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-2.png\" alt=\"\" class=\"wp-image-33\" srcset=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-2.png 377w, https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-2-300x244.png 300w\" sizes=\"auto, (max-width: 377px) 100vw, 377px\" \/><\/figure>\n\n\n\n<p><strong>Network Namespace, the building block of Container Networking.<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Network namespace is the core technology that fuels the container networking.Linux contains various features to provide multi-tenant support on host. Various namespace provided different kind of isolation(can be sen from above diagram) where network namespace provides networking resource isolation exclusively.<\/p>\n\n\n\n<p>Network namespace provide isolation of the following networking resource in the system:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"791\" height=\"459\" src=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-11.png\" alt=\"\" class=\"wp-image-57\" srcset=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-11.png 791w, https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-11-300x174.png 300w, https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-11-768x446.png 768w\" sizes=\"auto, (max-width: 791px) 100vw, 791px\" \/><\/figure>\n\n\n\n<p>Lets demo the network namespace concepts.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create two network namespace namely Producer and Consumer using linux ip command<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>master$ip netns add producer\n\nmaster$ip netns add consumer\n\nmaster$ip netns list\n\nproducer\n\nConsumer<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"692\" height=\"365\" src=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-3.png\" alt=\"\" class=\"wp-image-34\" srcset=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-3.png 692w, https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-3-300x158.png 300w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a virtual enternet cable(veth) with connectors at both end, we will be using the virtual ethernet to connect the network namespace<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>master$ip link add veth-producer type veth peer name veth-consumer\n\nmaster$ip link list | grep veth\n\n20: veth-consumer@veth-producer: &lt;BROADCAST,MULTICAST,M-DOWN&gt; mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000\n\n21: veth-producer@veth-consumer: &lt;BROADCAST,MULTICAST,M-DOWN&gt; mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"692\" height=\"370\" src=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-4.png\" alt=\"\" class=\"wp-image-35\" srcset=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-4.png 692w, https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-4-300x160.png 300w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The veth exists on host, lets assign the veth to the created namespaces.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>master$ip link set veth-producer netns producer\n\nmaster$ip link set veth-consumer netns consumer\n\nmaster$ip link list | grep veth &nbsp;&nbsp;&nbsp;&nbsp;\/\/ Wont give any ouput as the veth has moved to namespace on which it get assigned<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"692\" height=\"327\" src=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-5.png\" alt=\"\" class=\"wp-image-36\" srcset=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-5.png 692w, https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-5-300x142.png 300w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/figure>\n\n\n\n<p>Lets check the producer and consumer namespace<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"779\" height=\"135\" src=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-6.png\" alt=\"\" class=\"wp-image-37\" srcset=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-6.png 779w, https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-6-300x52.png 300w, https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-6-768x133.png 768w\" sizes=\"auto, (max-width: 779px) 100vw, 779px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Assign the IP\u2019s and make the interfaces up<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"165\" src=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-7.png\" alt=\"\" class=\"wp-image-38\" srcset=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-7.png 693w, https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-7-300x71.png 300w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"692\" height=\"190\" src=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-8.png\" alt=\"\" class=\"wp-image-39\" srcset=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-8.png 692w, https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-8-300x82.png 300w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"692\" height=\"328\" src=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-9.png\" alt=\"\" class=\"wp-image-40\" srcset=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-9.png 692w, https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-9-300x142.png 300w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using ping command , validate the network namespaces are connected and reachable.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"647\" height=\"420\" src=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-10.png\" alt=\"\" class=\"wp-image-41\" srcset=\"https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-10.png 647w, https:\/\/aiinfrahub.com\/wp-content\/uploads\/2024\/11\/image-10-300x195.png 300w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/figure>\n\n\n\n<p>We have reached the end of this article where we have understood the significance of namespaces. Also we have done hands-on using network namespace, we have created namespace, virtual ethernet, assigned them to created namespaces , assigned ip address and then validated the connectivity between two namespaces.<\/p>\n\n\n\n<p>Now, there is a serious scalability issue with this approach. As the no of namespaces increases we will face tremendous challenge in creating veth pair and connecting the namespace.<\/p>\n\n\n\n<p>Rescue is done by&nbsp;Linux bridge&nbsp;which can tap these network namespaces to the bridge to get connectivity. The same concept applied to the Docker where it sets up networking between containers running on the same host.<\/p>\n\n\n\n<p>We will go over the linux bridge concept and demo in the next chapter.<\/p>\n\n\n\n<p>Good Bye for now.<\/p>\n\n\n\n<p>References:<\/p>\n\n\n\n<p><a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/network_namespaces.7.html\">https:\/\/man7.org\/linux\/man-pages\/man7\/network_namespaces.7.html<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux Namespaces are operating system constructs which provides a containers the required isolation so that resources of one container shall not interfere with others containers and the host. In other words, we make sure that a process running in one container can\u2019t easily interfere with the operation of another container or the underlying host? Linux &#8230; <a title=\"Linux Network Namespace\" class=\"read-more\" href=\"https:\/\/aiinfrahub.com\/about-us\/linux-network-namespace\/\" aria-label=\"Read more about Linux Network Namespace\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":53,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-1","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-kubernetes","category-networking"],"_links":{"self":[{"href":"https:\/\/aiinfrahub.com\/about-us\/wp-json\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiinfrahub.com\/about-us\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiinfrahub.com\/about-us\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiinfrahub.com\/about-us\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aiinfrahub.com\/about-us\/wp-json\/wp\/v2\/comments?post=1"}],"version-history":[{"count":8,"href":"https:\/\/aiinfrahub.com\/about-us\/wp-json\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":72,"href":"https:\/\/aiinfrahub.com\/about-us\/wp-json\/wp\/v2\/posts\/1\/revisions\/72"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aiinfrahub.com\/about-us\/wp-json\/wp\/v2\/media\/53"}],"wp:attachment":[{"href":"https:\/\/aiinfrahub.com\/about-us\/wp-json\/wp\/v2\/media?parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiinfrahub.com\/about-us\/wp-json\/wp\/v2\/categories?post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiinfrahub.com\/about-us\/wp-json\/wp\/v2\/tags?post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}