{"id":4706,"date":"2022-10-13T08:17:14","date_gmt":"2022-10-13T08:17:14","guid":{"rendered":"https:\/\/newdesign.sparksupport.com\/blog\/?p=4706"},"modified":"2024-06-21T11:47:47","modified_gmt":"2024-06-21T11:47:47","slug":"learn-network-namespaces","status":"publish","type":"post","link":"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/","title":{"rendered":"Learn Network Namespaces"},"content":{"rendered":"<p>In this blog, we gonna learn how network namespaces works.<\/p>\n<p>First off, install openvswitch in your Ubuntu<\/p>\n<p><code>apt-get update<\/code><br \/>\n<code>apt-get install openvswitch-switch<\/code><\/p>\n<p>Now let us create a namespace<\/p>\n<p><code>ip netns add red <\/code><br \/>\n<code>ip netns add blue <\/code><\/p>\n<p>You can seen these new namespaces created at<\/p>\n<p><code>ls \/var\/run\/netns<br \/>\nred blue <\/code><\/p>\n<p>In order to see the ip link at each namespaces<\/p>\n<p><code> ip netns exec red ip link <\/code><\/p>\n<p><code>1: lo:  mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000<br \/>\nlink\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 <\/code><\/p>\n<p>Similar will be the case with the blue namespace<\/p>\n<p>In order the red to communicate with blue namespace, they needs to connected via virtual switch. For this we use OVS.<br \/>\nWe will first create a virtual bridge using <strong>Openswitch <\/strong> or <strong>Linux Bridge<\/strong> We will show both ways here.<\/p>\n<p>First <strong>OpenSwitch<\/strong><\/p>\n<p><code> ovs-vsctl add-br OVS1<\/code><\/p>\n<p>This will create a bridge named OVS1 with a default interface OVS1<\/p>\n<p>Next to show the virtual switch<\/p>\n<p><code> ovs-vsctl show <\/code><br \/>\n<code> cf8eb0c9-306c-47ee-8149-a6caa10584ed<br \/>\nBridge OVS1<br \/>\nPort OVS1<br \/>\nInterface OVS1<br \/>\ntype: internal<br \/>\novs_version: \"2.13.8\" <\/code><\/p>\n<p>Now in the root namespace or in the host if you issue &#8220;ip link&#8221; command you will see the interface OVS1 added<\/p>\n<p><code>ip link<\/code><\/p>\n<p>We have red, blue and OVS1 namespaces and now lets connect altogether, for this we veth interfaces. Veth acts like a pipe connecting<br \/>\nthese namespaces<\/p>\n<p><code>ip link add eth0-r type veth peer name veth-r<\/code><br \/>\nWe will connect eth0-r in red namespace and veth-r in OVS1 namespace<\/p>\n<p><code>ip link set eth0-r netns red <\/code><br \/>\nNow you no longer can see eth0-r in host or root namespace but it can be seen in the &#8220;red namespace&#8221; You can verify this by<br \/>\n&#8220;ip netns exec red ip link&#8221;<\/p>\n<p>Now to add the other end to OVS issue the command<\/p>\n<p><code>ovs-vsctl add-port OVS1 veth-r <\/code><\/p>\n<p>The veth-r will be now in OVS1 switch<\/p>\n<p><code>ip link set dev veth-r up<\/code> #This is important<\/p>\n<p><code>ovs-vsctl show<\/code><br \/>\n<code>cf8eb0c9-306c-47ee-8149-a6caa10584ed<br \/>\nBridge OVS1<br \/>\nPort OVS1<br \/>\nInterface OVS1<br \/>\ntype: internal<br \/>\nPort veth-r<br \/>\nInterface veth-r<br \/>\novs_version: \"2.13.8\"<\/code><\/p>\n<p>Let us repeat the entire steps for the blue namespace as well<\/p>\n<p><code>ip link add eth0-b type veth peer name veth-b<\/code><br \/>\n<code>ip link set eth0-b netns blue <\/code><br \/>\n<code>ovs-vsctl add-port OVS1 veth-b<\/code><\/p>\n<p><code>ip link set dev veth-b up  #This is important<\/code><\/p>\n<p>Now the network is set, but all the links are down and without an IP to communicate. So let&#8217;s follow the below steps<\/p>\n<p><code>ip netns exec red ip link set dev lo up<\/code><br \/>\n<code>ip netns exec red ip link set dev eth0-r up<\/code><br \/>\n<code>ip netns exec red ip address add 10.0.0.1\/24 dev eth0-r<\/code><\/p>\n<p>Similar for blue<\/p>\n<p><code>ip netns exec blue  ip link set dev lo up<\/code><br \/>\n<code>ip netns exec blue ip link set dev eth0-b up<\/code><br \/>\n<code>ip netns exec blue ip address add 10.0.0.2\/24 dev eth0-b<\/code><\/p>\n<p>Instead of using <code>ip netns exec blue\/red<\/code> We can directly enter the namespace of each by<\/p>\n<p><code>ip netns exec blue\/red bash<\/code> and execute the <code>ip link<\/code> commands directly. You can type &#8220;exit&#8221; to get out of that<br \/>\nparticular namespace.<\/p>\n<p>Now try pinging<\/p>\n<p><strong>If you are going with Linux Bridge follow the below steps<\/strong><\/p>\n<p>ip link add linbr-0 type bridge<\/p>\n<p><code> ip link add veth-red type veth peer name veth-red-br<br \/>\nip link add veth-green type veth peer name veth-green-br<br \/>\nip link set veth-red netns red<br \/>\nip link set veth-red-br master linbr-0<br \/>\nip link set veth-green netns green<br \/>\nip link set veth-green-br master linbr-0<br \/>\nip -n red addr add 10.0.0.1\/24 dev veth-red<br \/>\nip -n green addr add 10.0.0.2\/24 dev veth-green<br \/>\nip -n red link set veth-red up<br \/>\nip link set veth-red-br up<br \/>\nip -n green link set veth-green up<br \/>\nip link set veth-green-br up<br \/>\nip addr add 10.0.0.10\/24 dev linbr-0<br \/>\nip netns exec red bash<br \/>\nping 10.0.0.2 <\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we gonna learn how network namespaces works. First off, install openvswitch in your Ubuntu apt-get update apt-get install openvswitch-switch Now let us<\/p>\n","protected":false},"author":3,"featured_media":5026,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-4706","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Learn Network Namespaces -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn Network Namespaces -\" \/>\n<meta property=\"og:description\" content=\"In this blog, we gonna learn how network namespaces works. First off, install openvswitch in your Ubuntu apt-get update apt-get install openvswitch-switch Now let us\" \/>\n<meta property=\"og:url\" content=\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-13T08:17:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-06-21T11:47:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2022\/10\/image_thumb1.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"478\" \/>\n\t<meta property=\"og:image:height\" content=\"463\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Shijil T S\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shijil T S\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/\"},\"author\":{\"name\":\"Shijil T S\",\"@id\":\"https:\/\/sparksupport.com\/blog\/#\/schema\/person\/22359d1be71d2034f0fcfad7bb1d20e1\"},\"headline\":\"Learn Network Namespaces\",\"datePublished\":\"2022-10-13T08:17:14+00:00\",\"dateModified\":\"2024-06-21T11:47:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/\"},\"wordCount\":314,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2022\/10\/image_thumb1.webp\",\"articleSection\":[\"linux\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/\",\"url\":\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/\",\"name\":\"Learn Network Namespaces -\",\"isPartOf\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2022\/10\/image_thumb1.webp\",\"datePublished\":\"2022-10-13T08:17:14+00:00\",\"dateModified\":\"2024-06-21T11:47:47+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#primaryimage\",\"url\":\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2022\/10\/image_thumb1.webp\",\"contentUrl\":\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2022\/10\/image_thumb1.webp\",\"width\":478,\"height\":463},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/sparksupport.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Learn Network Namespaces\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/sparksupport.com\/blog\/#website\",\"url\":\"https:\/\/sparksupport.com\/blog\/\",\"name\":\"SparkSupport Blog\",\"description\":\"SparkSupport Blogs\",\"publisher\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/sparksupport.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/sparksupport.com\/blog\/#organization\",\"name\":\"SparkSupport\",\"url\":\"https:\/\/sparksupport.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/sparksupport.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2019\/08\/cropped-logo-1.jpg\",\"contentUrl\":\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2019\/08\/cropped-logo-1.jpg\",\"width\":216,\"height\":44,\"caption\":\"SparkSupport\"},\"image\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/sparksupport.com\/blog\/#\/schema\/person\/22359d1be71d2034f0fcfad7bb1d20e1\",\"name\":\"Shijil T S\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/b230de1fe222ae355698bc2670ef7c4290aef391ab75b46d111dc54cb3ab0e99?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b230de1fe222ae355698bc2670ef7c4290aef391ab75b46d111dc54cb3ab0e99?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b230de1fe222ae355698bc2670ef7c4290aef391ab75b46d111dc54cb3ab0e99?s=96&d=mm&r=g\",\"caption\":\"Shijil T S\"},\"description\":\"Hi All.. I am the CEO of SparkSupport and a Certified Kubernetes Expert, passionate about delivering innovative technology solutions and helping teams achieve their best.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/shijils\/\"],\"url\":\"https:\/\/sparksupport.com\/blog\/author\/shijil\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learn Network Namespaces -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/","og_locale":"en_US","og_type":"article","og_title":"Learn Network Namespaces -","og_description":"In this blog, we gonna learn how network namespaces works. First off, install openvswitch in your Ubuntu apt-get update apt-get install openvswitch-switch Now let us","og_url":"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/","article_published_time":"2022-10-13T08:17:14+00:00","article_modified_time":"2024-06-21T11:47:47+00:00","og_image":[{"width":478,"height":463,"url":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2022\/10\/image_thumb1.webp","type":"image\/webp"}],"author":"Shijil T S","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Shijil T S","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#article","isPartOf":{"@id":"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/"},"author":{"name":"Shijil T S","@id":"https:\/\/sparksupport.com\/blog\/#\/schema\/person\/22359d1be71d2034f0fcfad7bb1d20e1"},"headline":"Learn Network Namespaces","datePublished":"2022-10-13T08:17:14+00:00","dateModified":"2024-06-21T11:47:47+00:00","mainEntityOfPage":{"@id":"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/"},"wordCount":314,"commentCount":0,"publisher":{"@id":"https:\/\/sparksupport.com\/blog\/#organization"},"image":{"@id":"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#primaryimage"},"thumbnailUrl":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2022\/10\/image_thumb1.webp","articleSection":["linux"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/","url":"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/","name":"Learn Network Namespaces -","isPartOf":{"@id":"https:\/\/sparksupport.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#primaryimage"},"image":{"@id":"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#primaryimage"},"thumbnailUrl":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2022\/10\/image_thumb1.webp","datePublished":"2022-10-13T08:17:14+00:00","dateModified":"2024-06-21T11:47:47+00:00","breadcrumb":{"@id":"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#primaryimage","url":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2022\/10\/image_thumb1.webp","contentUrl":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2022\/10\/image_thumb1.webp","width":478,"height":463},{"@type":"BreadcrumbList","@id":"https:\/\/sparksupport.com\/blog\/learn-network-namespaces\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/sparksupport.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Learn Network Namespaces"}]},{"@type":"WebSite","@id":"https:\/\/sparksupport.com\/blog\/#website","url":"https:\/\/sparksupport.com\/blog\/","name":"SparkSupport Blog","description":"SparkSupport Blogs","publisher":{"@id":"https:\/\/sparksupport.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/sparksupport.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/sparksupport.com\/blog\/#organization","name":"SparkSupport","url":"https:\/\/sparksupport.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/sparksupport.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2019\/08\/cropped-logo-1.jpg","contentUrl":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2019\/08\/cropped-logo-1.jpg","width":216,"height":44,"caption":"SparkSupport"},"image":{"@id":"https:\/\/sparksupport.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/sparksupport.com\/blog\/#\/schema\/person\/22359d1be71d2034f0fcfad7bb1d20e1","name":"Shijil T S","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b230de1fe222ae355698bc2670ef7c4290aef391ab75b46d111dc54cb3ab0e99?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b230de1fe222ae355698bc2670ef7c4290aef391ab75b46d111dc54cb3ab0e99?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b230de1fe222ae355698bc2670ef7c4290aef391ab75b46d111dc54cb3ab0e99?s=96&d=mm&r=g","caption":"Shijil T S"},"description":"Hi All.. I am the CEO of SparkSupport and a Certified Kubernetes Expert, passionate about delivering innovative technology solutions and helping teams achieve their best.","sameAs":["https:\/\/www.linkedin.com\/in\/shijils\/"],"url":"https:\/\/sparksupport.com\/blog\/author\/shijil\/"}]}},"_links":{"self":[{"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/posts\/4706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/comments?post=4706"}],"version-history":[{"count":0,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/posts\/4706\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/media\/5026"}],"wp:attachment":[{"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/media?parent=4706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/categories?post=4706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/tags?post=4706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}