{"id":2152,"date":"2020-07-06T08:53:16","date_gmt":"2020-07-06T05:53:16","guid":{"rendered":"https:\/\/upcloud.com\/global\/us\/resources\/tutorials\/connect-private-networks-sdn-router-api\/"},"modified":"2020-07-06T08:53:16","modified_gmt":"2020-07-06T05:53:16","slug":"connect-private-networks-sdn-router-api","status":"publish","type":"tutorial","link":"https:\/\/upcloud.com\/global\/resources\/tutorials\/connect-private-networks-sdn-router-api\/","title":{"rendered":"How to connect private networks using SDN Router API"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Using SDN Private Networks, you have a lot of freedom to configure secure connectivity between your cloud servers. With the introduction of SDN Router API, you can create a gateway between any number of SDN Private Networks within a data centre.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SDN Routers are expanding the customisation possibilities of SDN Private Networking.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you are not yet familiar with the UpCloud API, we would suggest taking a quick look at our guide to&nbsp;<a href=\"https:\/\/upcloud.com\/global\/resources\/tutorials\/getting-started-upcloud-api\">getting started with UpCloud API<\/a>&nbsp;to set up your API user account and access rights.<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/signup.upcloud.com\/\">Test hosting on UpCloud!<\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Creating a new SDN router<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">SDN Router API makes it very simple to connect existing SDN Private Networks without added complexity or new IP addresses to configure. Getting started managing SDN Routers via the <a rel=\"noopener\" href=\"https:\/\/developers.upcloud.com\/1.3\/13-networks\/\" target=\"_blank\">UpCloud API<\/a> is quick and easy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can get the list of all currently available routers using the following request. By default, you\u2019ll only see the Utility Router connecting your cloud servers across your whole account.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">GET \/1.3\/router\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You will get a response with just the default router for the Utility network.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n   \"routers\": {\n      \"router\": [\n         {\n            \"attached_networks\": {\n               \"network\": [\n                  {\n                     \"uuid\": \"039fe709-053a-4790-9290-572e2c32ba0e\"\n                  }\n               ]\n            },\n            \"name\": \"Utility network router for zone fi-hel1\",\n            \"type\": \"service\",\n            \"uuid\": \"04104678-d957-4c4d-9775-46621f2841e1\"\n         }\n      ]\n   }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Deploy a new router by sending a request that includes the following body formatted in JSON to name your router.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">POST \/1.3\/router\/<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n   \"router\": {\n      \"name\": \"My Router\"\n   }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If successful, you\u2019ll get a response similar to the example below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n   \"router\": {\n      \"attached_networks\": {\n         \"network\": []\n      },\n      \"name\": \"My Router\",\n      \"type\": \"normal\",\n      \"uuid\": \"04f42ad3-309e-43fc-8576-68869fdf5678\"\n   }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Your new router will then appear on the list of available routers if you query it again.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Attaching network<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once you\u2019ve created your first SDN Router, you can begin attaching SDN Private Networks. If you haven\u2019t yet got started with SDN Private Networks, check out our tutorial on <a href=\"https:\/\/upcloud.com\/global\/resources\/tutorials\/configure-sdn-private-networks-upcloud-api\">how to configure SDN Private Networks using the UpCloud API<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In practice, attaching private networks to a router works by setting the router parameter in the network details to match the UUID of the router you wish to connect to. Each network can only be attached to one router at a time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check the UUID of your SDN Router in response to creating it, then set the router UUID in the details of your SDN Private Network. Replace the UUIDs in the following request and body message accordingly.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">PUT \/1.3\/network\/<span style=\"color: #ff0000;\">{network-uuid}<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n   \"network\": {\n      \"router\": \"<span style=\"color: #ff0000;\">{router-uuid}<\/span>\"\n   }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If your network was successfully attached to the router, you\u2019ll see a response similar to the example below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n   \"network\": {\n      \"ip_networks\": {\n         \"ip_network\": [\n            {\n               \"address\": \"11.0.0.0\/24\",\n               \"dhcp\": \"yes\",\n               \"dhcp_default_route\": \"no\",\n               \"family\": \"IPv4\",\n               \"gateway\": \"11.0.0.1\"\n            }\n         ]\n      },\n      \"name\": \"Private network 1\",\n      \"router\": \"04f42ad3-309e-43fc-8576-68869fdf5678\",\n      \"type\": \"private\",\n      \"uuid\": \"035661db-570c-4c46-9903-6dc890f56343\",\n      \"zone\": \"fi-hel1\"\n   }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can find the UUIDs of your SDN Private Networks using the following request.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">GET \/1.3\/network\/<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n   \"networks\": {\n      \"network\": [\n         ...\n         {\n            \"ip_networks\": {\n               \"ip_network\": [...]\n            },\n            \"name\": \"Private network 1\",\n            \"servers\": {\n               \"server\": [...]\n            },\n            \"type\": \"private\",\n            \"uuid\": \"<span style=\"color: #00ff00;\">035661db-570c-4c46-9903-6dc890f56343<\/span>\",\n            \"zone\": \"fi-hel1\"\n         },\n         {\n            \"ip_networks\": {\n               \"ip_network\": [...]\n            },\n            \"name\": \"Private network 2\",\n            \"servers\": {\n               \"server\": [...]\n            },\n            \"type\": \"private\",\n            \"uuid\": \"<span style=\"color: #00ff00;\">03beb27f-73a5-4333-93fd-7052b7b0791b<\/span>\",\n            \"zone\": \"fi-hel1\"\n         }\n      ]\n   }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once your private networks are connected via the router, you still need to create new routes to enable communication between the private networks. To accomplish this log into the cloud servers and add the relevant routes between the networks to their corresponding network interfaces.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, to add a route between SDN Priavet Networks with the IP ranges of <tt>11.0.0.0\/24<\/tt> and <tt>12.0.0.0\/24<\/tt>, you\u2019ll need to add the following rule on cloud servers connected to <tt>11.0.0.0\/24<\/tt> with the gateway <tt>11.0.0.1<\/tt>. Replace the IP addresses and the network interface <tt>eth3<\/tt> in the example with your network details.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ip route add 12.0.0.0\/24 via 11.0.0.1 dev eth3<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Afterwards, if you check the configured routes with the next command, you should see the new route connecting to the other private network.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ip route<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">...\n11.0.0.0\/24 dev eth3 proto kernel scope link src 11.0.0.2 metric 102\n12.0.0.0\/24 via 11.0.0.1 dev eth3 proto dhcp metric 102<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Repeat these steps on each cloud server you want to use between the private networks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it! Your cloud servers connected to either private network can now communicate via the router gateway.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Detaching networks<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When you no longer need to connect a specific SDN Private Network, you can detach it from your router at any point.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To detach a network from a router, set the router in your network details to empty.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">PUT \/1.3\/network\/<span style=\"color: #ff0000;\">{network-uuid}<\/span><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n   \"network\": {\n      \"router\": \"\"\n &nbsp; &nbsp;}\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You will then get a response to confirm your private network has been detached. Note that the router parameter is no longer present.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n   \"network\": {\n      \"ip_networks\": {\n         \"ip_network\": [\n            {\n               \"address\": \"11.0.0.0\/24\",\n               \"dhcp\": \"yes\",\n               \"dhcp_default_route\": \"no\",\n               \"family\": \"IPv4\",\n               \"gateway\": \"11.0.0.1\"\n            }\n         ]\n      },\n      \"name\": \"Private network 1\",\n      \"type\": \"private\",\n      \"uuid\": \"035661db-570c-4c46-9903-6dc890f56343\",\n      \"zone\": \"fi-hel1\"\n   }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The selected network will then have been detached from your router.<\/p>\n","protected":false},"author":3,"featured_media":15760,"comment_status":"open","ping_status":"closed","template":"","community-category":[271,259,247],"class_list":["post-2152","tutorial","type-tutorial","status-publish","has-post-thumbnail","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial"}],"about":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/types\/tutorial"}],"author":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/comments?post=2152"}],"version-history":[{"count":0,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2152\/revisions"}],"wp:attachment":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/media?parent=2152"}],"wp:term":[{"taxonomy":"community-category","embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/community-category?post=2152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}