
{"id":23586,"date":"2025-05-07T19:46:33","date_gmt":"2025-05-07T17:46:33","guid":{"rendered":"https:\/\/contabo.com\/blog\/kb\/103000343650-how-can-i-setup-a-static-route\/"},"modified":"2025-05-07T19:46:33","modified_gmt":"2025-05-07T17:46:33","slug":"103000343650-how-can-i-setup-a-static-route","status":"publish","type":"kb","link":"https:\/\/contabo.com\/blog\/kb\/103000343650-how-can-i-setup-a-static-route\/","title":{"rendered":"How Can I Setup a Static Route?"},"content":{"rendered":"<h4 data-end=\"297\" data-start=\"169\" dir=\"ltr\" id=\"Overview:\"><strong>Overview:<\/strong><\/h4>\n<p dir=\"ltr\">Static routes are manually configured paths that instruct a device on how to reach specific networks. They are particularly useful in small networks, offering enhanced control and security, or as a backup to dynamic routes.&nbsp;<\/p>\n<p dir=\"ltr\"><\/p>\n<p dir=\"ltr\">Static routes can be used for various setups, such as connecting different subnets, routing VPN traffic, or ensuring traffic takes a specific path.<\/p>\n<p data-end=\"545\" data-start=\"299\" dir=\"ltr\"><\/p>\n<p data-end=\"545\" data-start=\"299\" dir=\"ltr\">Below you&#8217;ll find guides for setting up a static route on your server depending on the type of operating system you are using.<\/p>\n<p data-end=\"545\" data-start=\"299\" dir=\"ltr\"><\/p>\n<p data-end=\"545\" data-start=\"299\" dir=\"ltr\">The following examples will use the IP addresses <code>192.51.100.10<\/code> and <code>192.51.100.42<\/code>, please make sure to change the examples with your own IP addresses.<\/p>\n<p data-end=\"545\" data-start=\"299\" dir=\"ltr\"><\/p>\n<h4 class=\"fd-toc\"><strong dir=\"ltr\">Table of contents:<\/strong><\/h4>\n<ul>\n<li><a dir=\"ltr\" href=\"#What-information-do-I-need-to-setup-a-static-route\" rel=\"nofollow\">What information do I need to setup a static route?<\/a><\/li>\n<li><a href=\"#How-do-I-setup-a-static-route-on-CentOS\" rel=\"nofollow\">How do I setup a static route on CentOS?<\/a><\/li>\n<li><a href=\"#How-do-I-setup-a-static-route-on-Debian\/Ubuntu(Until-version-17.04)\" rel=\"nofollow\">How do I setup a static route on Debian\/Ubuntu(Until version 17.04)?<\/a><\/li>\n<li><a href=\"#How-do-I-setup-a-static-route-on-Ubuntu-(Version-17.10-and-above)\" rel=\"nofollow\">How do I setup a static route on Ubuntu (Version 17.10 and above)?<\/a><\/li>\n<li><a href=\"#How-do-I-setup-a-static-route-on-openSUSE\" rel=\"nofollow\">How do I setup a static route on openSUSE?<\/a><\/li>\n<li><a href=\"#How-do-I-setup-a-static-route-on-Windows\" rel=\"nofollow\">How do I setup a static route on Windows?<\/a><\/li>\n<\/ul>\n<p data-end=\"545\" data-start=\"299\" dir=\"ltr\"><\/p>\n<h4 data-end=\"545\" data-start=\"299\" dir=\"ltr\" id=\"What-information-do-I-need-to-setup-a-static-route?\"><strong>What information do I need to setup a static route?<\/strong><\/h4>\n<p dir=\"ltr\">You will need the following information to setup a static route:<\/p>\n<ul>\n<li dir=\"ltr\">The IP addresses.<\/li>\n<li dir=\"ltr\">The subnets.<\/li>\n<li dir=\"ltr\">The gateways.\n<\/li>\n<\/ul>\n<p dir=\"ltr\">If you&#8217;re not sure how to find this info, you can follow our <u><a href=\"https:\/\/help.contabo.com\/en\/support\/solutions\/articles\/103000342389-how-can-i-check-the-ip-address-of-my-server-and-configuration-details-in-the-customer-control-panel-\" rel=\"noopener noreferrer nofollow\" target=\"_blank\"><u>guide here<\/u><\/a><\/u>.<\/p>\n<h4 data-end=\"545\" data-start=\"299\" dir=\"ltr\" id=\"\"><\/h4>\n<h4 data-end=\"545\" data-start=\"299\" dir=\"ltr\" id=\"How-do-I-setup-a-static-route-on-CentOS?\"><strong dir=\"ltr\">How do I setup a static route on CentOS?<\/strong><\/h4>\n<ol>\n<li dir=\"ltr\">Open the network configuration file. If you use eth0, the file is called route-eth0 and located under \/etc\/sysconfig\/network-scripts\/.&nbsp;<\/li>\n<li dir=\"ltr\">Add the below entry to setup a static server from 192.51.100.10 to 192.51.100.42:\n<pre>#\/etc\/sysconfig\/network-scripts\/route-eth0\n ...\n 192.51.100.42\/32 via 192.51.100.1 dev eth0<\/pre>\n<\/li>\n<li dir=\"ltr\">Add the below entry to setup a route from 192.51.100.42 to 192.51.100.10:\n<pre>#\/etc\/sysconfig\/network-scripts\/route-eth0\n ...\n&nbsp;192.51.100.10\/32 via 192.51.100.1 dev eth0<\/pre>\n<\/li>\n<li dir=\"ltr\">Alternatively, both servers can have a single route added to the whole \/24 subnet by adding the following:\n<pre>#\/etc\/sysconfig\/network-scripts\/route-eth0\n ...\n 192.51.100.0\/24 via 192.51.100.1 dev eth0<\/pre>\n<\/li>\n<\/ol>\n<h4 data-end=\"545\" data-start=\"299\" dir=\"ltr\" id=\"How-do-I-setup-a-static-route-on-Debian\/Ubuntu(Until-version-17.04)?\"><strong dir=\"ltr\">How do I setup a static route on Debian\/Ubuntu(Until version 17.04)?<\/strong><\/h4>\n<ol>\n<li dir=\"ltr\">Open the network configuration file \/etc\/network\/interfaces. Entries are added to the end of the file or under the iface sections of the respective interface. Assuming the interface to be eth0, the entry on server 192.51.100.10 would look like this:\n<pre>#\/etc\/network\/interfaces\n ...\n up ip route add 192.51.100.42\/32 via 192.51.100.1 dev eth0\n down ip route del 192.51.100.42\/32 via 192.51.100.1 dev eth0<\/pre>\n<\/li>\n<li dir=\"ltr\">On server 192.51.100.42, this would be the static route to 192.51.100.10:\n<pre dir=\"ltr\">#\/etc\/network\/interfaces\n ...\n up ip route add 192.51.100.10\/32 via 192.51.100.1 dev eth0\n&nbsp;down ip route del 192.51.100.10\/32 via 192.51.100.1 dev eth0 <\/pre>\n<\/li>\n<li dir=\"ltr\">It is also possible to add a static route to the whole \/24 on both servers instead with the following configuration:\n<pre>#\/etc\/network\/interfaces\n ...\n up ip route add 192.51.100.0\/24 via 192.51.100.1 dev eth0\n down ip route del 192.51.100.0\/24 via 192.51.100.1 dev eth0<\/pre>\n<\/li>\n<\/ol>\n<h4 data-end=\"545\" data-start=\"299\" dir=\"ltr\" id=\"How-do-I-setup-a-static-route-on-Ubuntu-(Version-17.10-and-above)?\"><strong dir=\"ltr\">How do I setup a static route on Ubuntu (Version 17.10 and above)?<\/strong><\/h4>\n<ol>\n<li dir=\"ltr\">Open the network configuration file \/etc\/netplan\/01-netcfg.yaml.<\/li>\n<li dir=\"ltr\">On the server with the IP 192.51.100.10, the entry has to be added in the correct indentation to the network interface, which in our example is eth0. You would to add the two routes shown below for each server IP.\n<pre>#\/etc\/netplan\/01-netcfg.yaml\n...\n eth0:\n routes:\n - to: 192.51.100.0\/25\n   via: 192.51.100.1\n - to: 192.51.100.128\/25\n&nbsp; &nbsp;via: 192.51.100.1 <\/pre>\n<\/li>\n<li dir=\"ltr\">Finally, reset the routing table and to apply the changes. Please use the whole command at once to prevent a network connection loss:\n<pre>ip route flush table main; ip route flush cache; netplan apply<\/pre>\n<\/li>\n<\/ol>\n<h4 dir=\"ltr\" id=\"How-do-I-setup-a-static-route-on-openSUSE?\"><strong dir=\"ltr\">How do I setup a static route on openSUSE?<\/strong><\/h4>\n<ol>\n<li dir=\"ltr\">Open the network configuration file \/etc\/sysconfig\/network\/routes.&nbsp;<\/li>\n<li dir=\"ltr\">Add the following to setup a static route from 192.51.100.10 to 192.51.100.42:\n<pre>#\/etc\/sysconfig\/network\/routes\n ...\n 192.51.100.42\/32 192.51.100.1 - eth0<\/pre>\n<\/li>\n<li dir=\"ltr\">Add the following to setup a static route from 192.51.100.42 to 192.51.100.10:\n<pre dir=\"ltr\">#\/etc\/sysconfig\/network\/routes\n ...\n 192.51.100.10\/32 192.51.100.1 - eth0<\/pre>\n<\/li>\n<li dir=\"ltr\">As an alternative, both servers can have a static route to the whole \/24 subnet with the following configuration:\n<pre>#\/etc\/sysconfig\/network\/routes\n...\n 192.51.100.0\/24 192.51.100.1 - eth0<\/pre>\n<\/li>\n<\/ol>\n<h4 dir=\"ltr\" id=\"How-do-I-setup-a-static-route-on-Windows?\"><strong dir=\"ltr\">How do I setup a static route on Windows?<\/strong><\/h4>\n<ol>\n<li dir=\"ltr\">Open the &ldquo;Command Prompt&rdquo; with administrative privileges. Simply right-click on the Command Prompt icon in your Start panel and then click on &ldquo;Run as administrator&rdquo;:\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12991 webpexpress-processed fr-fic fr-dii\" src=\"https:\/\/s3-eu-central-1.amazonaws.com\/euc-cdn.freshdesk.com\/data\/helpdesk\/attachments\/production\/103212452378\/original\/tw_noCvCJIf5i2hosnkUlpaaLC26ZPj6ug.png?1746539699\" alt=\"command prompt admin\" width=\"341\" height=\"290\" data-id=\"103212452378\" data-attachment=\"[object Object]\">&nbsp;<\/li>\n<li dir=\"ltr\">On server 192.51.100.10 enter the following command:\n<pre>route -p add 192.51.100.42 mask 255.255.255.255 192.51.100.1<\/pre>\n<\/li>\n<li dir=\"ltr\">Setup the corresponding entry on server 192.51.100.42 with this command:\n<pre>route -p add 192.51.100.10 mask 255.255.255.255 192.51.100.1<\/pre>\n<\/li>\n<li dir=\"ltr\">Please note setting the -p option makes the route persistent across reboots. If the route is meant to be temporary, you may omit -p.<\/li>\n<li dir=\"ltr\">Since Windows automatically adds a default route to the whole subnet with a higher metric, it is necessary to also deactivate this default route. Otherwise, the new static route will not have any effect. Use the following command to delete the default route:\n<pre>route delete 192.51.100.0<\/pre>\n<\/li>\n<\/ol>\n<p dir=\"ltr\"><\/p>\n<p><\/p>\n<\/p>\n<p><span class=\"ast-load-more active\"><a href=\"https:\/\/help.contabo.com\/en\/support\/solutions\/articles\/103000343650-how-can-i-setup-a-static-route-\" rel=\"nofollow\">Details&#8230;<\/a> <\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview: Static routes are manually configured paths that instruct a device on how to reach specific networks. They are particularly useful in small networks, offering enhanced control and security, or as a backup to dynamic routes.&nbsp; Static routes can be used for various setups, such as connecting different subnets, routing VPN traffic, or ensuring traffic [&hellip;]<\/p>\n","protected":false},"author":72,"featured_media":0,"template":"","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":[],"tags":[],"class_list":["post-23586","kb","type-kb","status-publish","hentry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Contabo Web","author_link":"https:\/\/contabo.com\/blog\/author\/julius-nalivaiko\/"},"uagb_comment_info":0,"uagb_excerpt":"Overview: Static routes are manually configured paths that instruct a device on how to reach specific networks. They are particularly useful in small networks, offering enhanced control and security, or as a backup to dynamic routes.&nbsp; Static routes can be used for various setups, such as connecting different subnets, routing VPN traffic, or ensuring traffic&hellip;","_links":{"self":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/kb\/23586","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/kb"}],"about":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/types\/kb"}],"author":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/users\/72"}],"version-history":[{"count":0,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/kb\/23586\/revisions"}],"wp:attachment":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media?parent=23586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/categories?post=23586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/tags?post=23586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}