{"id":3111,"date":"2015-07-04T09:01:39","date_gmt":"2015-07-04T07:01:39","guid":{"rendered":"https:\/\/contabo.com\/blog\/?p=3111"},"modified":"2022-01-17T07:57:09","modified_gmt":"2022-01-17T06:57:09","slug":"creating-static-routes","status":"publish","type":"post","link":"https:\/\/contabo.com\/blog\/creating-static-routes\/","title":{"rendered":"Creating static routes"},"content":{"rendered":"<p>All traffic in our network has to pass through our core-routers, additionally switch ports are configured in such a way that they only accept ethernet frames with mac addresses originating from these routers. Consequently, no layer-2 traffic is forwarded between switch ports and direct communication between servers, even when on the same subnet, is not possible. If you have multiple servers with us which use IPv4 addresses from the same subnet (usually <code>\/24<\/code>), and you want these servers to exchange traffic between each other, you will have to create static routes on these servers to each other.<\/p>\n<p>The following examples assume that the server with the IPv4 address <code>192.51.100.10<\/code> and the server with the IPv4 address <code>192.51.100.42<\/code> want to communicate with each other.<\/p>\n<h2>CentOS<\/h2>\n<p>If you\u2019re not sure about your admin rights in Linux, always enter the command sudo -i at the beginning of every session:<br \/>\n<code><span style=\"color: #008000;\">sudo -i<\/span><\/code><br \/>\nThis command will grant you the rights of a power user, so you don\u2019t have to write the command sudo at the beginning of every command line.<\/p>\n<p>In CentOS, you can add static routes to the route-file of the respective interface. In case of <code>eth0<\/code>, the file is called <code>route-eth0<\/code> and located under <code>\/etc\/sysconfig\/network-scripts\/<\/code>. The below entry on server <code>192.51.100.10<\/code> adds a static to server <code>192.51.100.42:<\/code><\/p>\n<p><code><span style=\"color: #008000;\">#\/etc\/sysconfig\/network-scripts\/route-eth0<br \/>\n...<br \/>\n192.51.100.42\/32 via 192.51.100.1 dev eth0<br \/>\n<\/span><\/code><\/p>\n<p>Vice versa, the server <code>192.51.100.42<\/code> needs a corresponding route to server <code>192.51.100.10<\/code>:<\/p>\n<p><code><span style=\"color: #008000;\">#\/etc\/sysconfig\/network-scripts\/route-eth0<br \/>\n...<br \/>\n192.51.100.10\/32 via 192.51.100.1 dev eth0<br \/>\n<\/span><\/code><\/p>\n<p>Alternatively, both servers can have a single route added to the whole <code>\/24<\/code> subnet:<\/p>\n<p><code><span style=\"color: #008000;\">#\/etc\/sysconfig\/network-scripts\/route-eth0<br \/>\n...<br \/>\n192.51.100.0\/24 via 192.51.100.1 dev eth0<br \/>\n<\/span><\/code><\/p>\n<h2>Debian \/ Ubuntu (until 17.04)<\/h2>\n<p>Static routes in Debian and Ubuntu are saved to <code>\/etc\/network\/interfaces<\/code>. Entries are added to the end of the file or under the <code>iface<\/code> sections of the respective interface. Assuming the interface to be <code>eth0<\/code>,\u00a0 the entry on server <code>192.51.100.10<\/code> would look like this:<\/p>\n<p><code><span style=\"color: #008000;\">#\/etc\/network\/interfaces<br \/>\n...<br \/>\nup ip route add 192.51.100.42\/32 via 192.51.100.1 dev eth0<br \/>\ndown ip route del 192.51.100.42\/32 via 192.51.100.1 dev eth0<br \/>\n<\/span><\/code><\/p>\n<p>On server <code>192.51.100.42<\/code>, this would be the static route to <code>192.51.100.10<\/code>:<\/p>\n<p><code><span style=\"color: #008000;\">#\/etc\/network\/interfaces<br \/>\n...<br \/>\nup ip route add 192.51.100.10\/32 via 192.51.100.1 dev eth0<br \/>\ndown ip route del 192.51.100.10\/32 via 192.51.100.1 dev eth0<br \/>\n<\/span><\/code><\/p>\n<p>It is also possible to add a static route to the whole <code>\/24<\/code> on both servers instead:<\/p>\n<p><code><span style=\"color: #008000;\">#\/etc\/network\/interfaces<br \/>\n...<br \/>\nup ip route add 192.51.100.0\/24 via 192.51.100.1 dev eth0<br \/>\ndown ip route del 192.51.100.0\/24 via 192.51.100.1 dev eth0<br \/>\n<\/span><\/code><\/p>\n<h2>Ubuntu (17.10 and above)<\/h2>\n<p>In Ubuntu beginning with version 17.10, static routes are added to the file <code>\/etc\/netplan\/01-netcfg.yaml<\/code> . On the server with the IP \u00a0<code>192.51.100.10,<\/code>the entry has to be added in the correct indentation to the network interface, in this case\u00a0\u00a0<code>eth0<\/code> . Because of some <span class=\"tag_e\"><span class=\"tag_t\">particularities<\/span><\/span> in Netplan, there are two routes that have to be added for each server ip. Please note the prefixes that that got changed to \/25:<\/p>\n<pre><code><span style=\"color: #008000;\">#\/etc\/netplan\/01-netcfg.yaml\n<b>...<\/b>\n<b>    <\/b>eth0:\n<b>      <\/b>routes:\n<b>        <\/b>- to: 192.51.100.0\/25\n<b>          <\/b>via: 192.51.100.1\n<b>        <\/b>- to: 192.51.100.128\/25\n<b>          <\/b>via: 192.51.100.1\n<\/span><\/code><\/pre>\n<p>Finally it is required to reset the routing table and to apply the changes. Please use the whole command at once to prevent a network connection loss:<\/p>\n<p><code><span style=\"color: #008000;\">ip route flush table main; ip route flush cache; netplan apply<br \/>\n<\/span><\/code><\/p>\n<h2>openSUSE<\/h2>\n<p>Static routes in openSUSE can be set in <code>\/etc\/sysconfig\/network\/routes<\/code>. On server <code>192.51.100.10<\/code>, the static route to <code>192.51.100.42<\/code> is as follows:<\/p>\n<p><code><span style=\"color: #008000;\">#\/etc\/sysconfig\/network\/routes<br \/>\n...<br \/>\n192.51.100.42\/32 192.51.100.1 - eth0<br \/>\n<\/span><\/code><\/p>\n<p>Conversely, the static route on <code>192.51.100.42<\/code> to <code>192.51.100.10<\/code>:<\/p>\n<p><code><span style=\"color: #008000;\">#\/etc\/sysconfig\/network\/routes<br \/>\n...<br \/>\n192.51.100.10\/32 192.51.100.1 - eth0<br \/>\n<\/span><\/code><\/p>\n<p>As an alternative, both servers can have a static route to the whole <code>\/24<\/code> subnet:<\/p>\n<p><code><span style=\"color: #008000;\">#\/etc\/sysconfig\/network\/routes<br \/>\n...<br \/>\n192.51.100.0\/24 192.51.100.1 - eth0<br \/>\n<\/span><\/code><\/p>\n<h2>Windows Server<\/h2>\n<p>To create a static route under Windows Server 2012 or above, please open the &#8220;Command Prompt&#8221; with administrative privileges. Simply right-click on the Command Prompt icon in your Start panel and then click on &#8220;Run as administrator&#8221;:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12991\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/01\/Lkwp0drL3pv5Qu5I.png\" alt=\"command prompt admin\" width=\"341\" height=\"290\" \/><\/p>\n<p>On server <code>192.51.100.10<\/code> enter the following:<\/p>\n<p><code><span style=\"color: #008000;\">route -p add 192.51.100.42 mask 255.255.255.255 192.51.100.1<br \/>\n<\/span><\/code><\/p>\n<p>The corresponding entry on server <code>192.51.100.42 is:<\/code><\/p>\n<p><code><span style=\"color: #008000;\">route -p add 192.51.100.10 mask 255.255.255.255 192.51.100.1<br \/>\n<\/span><\/code><\/p>\n<p>Setting the <code>-p<\/code> option makes the route persistent across reboots. If the route is meant to be temporary, you may omit <code>-p<\/code>.<\/p>\n<p>Since Windows automatically adds a default route to the whole subnet with a higher metric, it is necessary to also deactive this default route. Otherwise, the new static route will not have any effect.<\/p>\n<p>Use the following command to delete the default route:<\/p>\n<p><code><span style=\"color: #008000;\"> route delete 192.51.100.0<\/span><\/code><\/p>\n<p>If you often reboot your server, it\u2019s advisable to create a little .bat script to perform this step automatically.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>All traffic in our network has to pass through our core-routers, additionally switch ports are configured in such a way that they only accept ethernet frames with mac addresses originating from these routers. Consequently, no layer-2 traffic is forwarded between switch ports and direct communication between servers, even when on the same subnet, is not [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18],"tags":[123,181,246,604,852,942],"ppma_author":[1515],"class_list":["post-3111","post","type-post","status-publish","format-standard","hentry","category-tutorials","tag-centos","tag-contabo","tag-debian","tag-opensuse","tag-ubuntu","tag-windows-server"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Andreas","author_link":"https:\/\/contabo.com\/blog\/author\/andreas-s\/"},"uagb_comment_info":0,"uagb_excerpt":"All traffic in our network has to pass through our core-routers, additionally switch ports are configured in such a way that they only accept ethernet frames with mac addresses originating from these routers. Consequently, no layer-2 traffic is forwarded between switch ports and direct communication between servers, even when on the same subnet, is not&hellip;","authors":[{"term_id":1515,"user_id":16,"is_guest":0,"slug":"andreas-s","display_name":"Andreas","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/4621d785e086973c75b9c513e62593de78eceac794ef2a785b4f31f75ebc902a?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/3111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/comments?post=3111"}],"version-history":[{"count":0,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/3111\/revisions"}],"wp:attachment":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media?parent=3111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/categories?post=3111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/tags?post=3111"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=3111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}