{"id":1315,"date":"2011-08-18T23:17:12","date_gmt":"2011-08-18T15:17:12","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=1315"},"modified":"2023-06-25T09:30:45","modified_gmt":"2023-06-25T09:30:45","slug":"how-to-add-static-routes-in-centos-5-6","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-add-static-routes-in-centos-5-6\/","title":{"rendered":"How to Add Static Routes in CentOS 5.6"},"content":{"rendered":"<p>In server administration, understanding how to manage static routes is a crucial skill.<\/p>\n<p>This guide will walk you through the process of adding static routes in CentOS 5.6, a popular Linux distribution often used in server environments. This tutorial was carried out on a <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-vps-hosting\/\">VPS server<\/a>, so the Network Interface Card (NIC) interface used is &#8216;venet0&#8217; instead of &#8216;eth0&#8217;. However, the steps remain the same regardless of your environment.<\/p>\n<p>It&#8217;s important to note that the configurations discussed here will be erased once the server is rebooted. If you want to permanently apply the routing table, you should use a persistent static route.<\/p>\n<h2>Understanding Your Original Routing Table<\/h2>\n<p>Before we begin, let&#8217;s take a look at the original routing table. You can view this by using the &#8216;netstat -rn&#8217; command. The output will look something like this:<\/p>\n<pre>\r\n[root@server ~]# netstat -rn\r\nKernel IP routing table\r\nDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface\r\n192.0.2.0       0.0.0.0         255.255.255.0   U         0 0          0 venet0\r\n169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 venet0\r\n0.0.0.0         0.0.0.0         0.0.0.0         U         0 0          0 venet0\r\n<\/pre>\n<p>The routing table contains information about IP routing and is crucial for the operation of an IP network.<\/p>\n<h2>Adding a Static Route for a Specific Network<\/h2>\n<p>To add a static route for a specific network in Linux, you can use the &#8216;route add&#8217; command followed by the &#8216;-net&#8217; option, the network address, and the gateway address. For example:<\/p>\n<pre>\r\n[root@server ~]# route add -net 192.168.2.0\/24 gw 192.168.13.1\r\n<\/pre>\n<p>After running this command, you can check the updated routing table with &#8216;netstat -rn&#8217;. You should see the new static route added to the table.<\/p>\n<pre>[root@server ~]# route add -net 192.168.2.0\/24 gw 192.168.13.1\r\n[root@server ~]# netstat -rn\r\nKernel IP routing table\r\nDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface\r\n192.168.2.0     192.168.13.1    255.255.255.0   UG        0 0          0 venet0\r\n192.0.2.0       0.0.0.0         255.255.255.0   U         0 0          0 venet0\r\n169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 venet0\r\n0.0.0.0         0.0.0.0         0.0.0.0         U         0 0          0 venet0<\/pre>\n<p>To delete a static route for a specific network, you can use the &#8216;route del&#8217; command followed by the &#8216;-net&#8217; option, the network address, and the gateway address. For example:<\/p>\n<pre>\r\n[root@server ~]# route del -net 192.168.2.0\/24 gw 192.168.13.1\r\n<\/pre>\n<p>After running this command, you can check the updated routing table with &#8216;netstat -rn&#8217;. The static route you added earlier should now be removed from the table.<\/p>\n<pre>[root@server ~]# route del -net 192.168.2.0\/24 gw 192.168.13.1\r\n[root@server ~]# netstat -rn\r\nKernel IP routing table\r\nDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface\r\n192.0.2.0       0.0.0.0         255.255.255.0   U         0 0          0 venet0\r\n169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 venet0\r\n0.0.0.0         0.0.0.0         0.0.0.0         U         0 0          0 venet0<\/pre>\n<h2>Adding a Static Route for a Specific Host<\/h2>\n<p>To add a static route for a specific host in Linux, you can use the &#8216;route add&#8217; command followed by the &#8216;-host&#8217; option, the host IP address, and the gateway address. For example:<\/p>\n<pre>\r\n[root@server ~]# route add -host 192.168.2.5 gw 192.168.13.1\r\n<\/pre>\n<p>After running this command, you can check the updated routing table with &#8216;netstat -rn&#8217;. You should see the new static route added to the table.<\/p>\n<pre>[root@server ~]# route add -host 192.168.2.5 gw 192.168.13.1\r\n[root@server ~]# netstat -rn\r\nKernel IP routing table\r\nDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface\r\n192.168.2.5     192.168.13.1    255.255.255.255 UGH       0 0          0 venet0\r\n192.0.2.0       0.0.0.0         255.255.255.0   U         0 0          0 venet0\r\n169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 venet0\r\n0.0.0.0         0.0.0.0         0.0.0.0         U         0 0          0 venet0<\/pre>\n<p>To delete a static route for a specific host, you can use the &#8216;route del&#8217; command followed by the &#8216;-host&#8217; option, the host IP address, and the gateway address. For example:<\/p>\n<pre>\r\n[root@server ~]#] route del -host 192.168.2.5 gw 192.168.13.1\r\n<\/pre>\n<p>After running this command, you can check the updated routing table with &#8216;netstat -rn&#8217;. The static route you added earlier should now be removed from the table.<\/p>\n<pre>[root@server ~]# route del -host 192.168.2.5 gw 192.168.13.1\r\n[root@server ~]# netstat -rn\r\nKernel IP routing table\r\nDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface\r\n192.0.2.0       0.0.0.0         255.255.255.0   U         0 0          0 venet0\r\n169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 venet0\r\n0.0.0.0         0.0.0.0         0.0.0.0         U         0 0          0 venet0<\/pre>\n<h2>Adding a Default Gateway<\/h2>\n<p>A default gateway is a device that forwards traffic from the local subnet to devices on other subnets. To add a default gateway in Linux, you can use the &#8216;route add&#8217; command followed by the &#8216;default&#8217; keyword and the gateway address. For example:<\/p>\n<pre>\r\n[root@server ~]# route add default gw 192.168.13.1\r\n<\/pre>\n<p>After running this command, you can check the updated routing table with &#8216;netstat -rn&#8217;. You should see the new default gateway added to the table.<\/p>\n<pre>\r\n[root@server ~]# route add default gw 192.168.13.1\r\n[root@server ~]# netstat -rn\r\nKernel IP routing table\r\nDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface\r\n192.0.2.0       0.0.0.0         255.255.255.0   U         0 0          0 venet0\r\n169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 venet0\r\n0.0.0.0         192.168.13.1    0.0.0.0         UG        0 0          0 venet0\r\n0.0.0.0         0.0.0.0         0.0.0.0         U         0 0          0 venet0<\/pre>\n<p>To delete a default gateway, you can use the &#8216;route del&#8217; command followed by the &#8216;default&#8217; keyword and the gateway address. For example:<\/p>\n<pre>\r\n[root@server ~]# route del default gw 192.168.13.1\r\n<\/pre>\n<p>After running this command, you can check the updated routing table with &#8216;netstat -rn&#8217;. The default gateway you added earlier should now be removed from the table.<\/p>\n<pre>\r\n[root@server ~]# route del default gw 192.168.13.1\r\n[root@server ~]# netstat -rn\r\nKernel IP routing table\r\nDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface\r\n192.0.2.0       0.0.0.0         255.255.255.0   U         0 0          0 venet0\r\n169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 venet0\r\n0.0.0.0         0.0.0.0         0.0.0.0         U         0 0          0 venet0<\/pre>\n<h2>Commands Mentioned<\/h2>\n<ul>\n<li><span class=\"fw-bold\">netstat -rn<\/span> \u2013 Displays the routing table<\/li>\n<li><span class=\"fw-bold\">route add -net [network address] gw [gateway address]<\/span> \u2013 Adds a static route for a specific network<\/li>\n<li><span class=\"fw-bold\">route del -net [network address] gw [gateway address]<\/span> \u2013 Deletes a static route for a specific network<\/li>\n<li><span class=\"fw-bold\">route add -host [host IP address] gw [gateway address]<\/span> \u2013 Adds a static route for a specific host<\/li>\n<li><span class=\"fw-bold\">route del -host [host IP address] gw [gateway address]<\/span> \u2013 Deletes a static route for a specific host<\/li>\n<li><span class=\"fw-bold\">route add default gw [gateway address]<\/span> \u2013 Adds a default gateway<\/li>\n<li><span class=\"fw-bold\">route del default gw [gateway address]<\/span> \u2013 Deletes a default gateway<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Understanding how to add and delete static routes in CentOS 5.6 is a fundamental skill for any server administrator. This guide has walked you through the process step-by-step, explaining how to add and delete static routes for specific networks and hosts, as well as how to add and delete a default gateway. Remember, these configurations will be erased once the server is rebooted, so if you want to permanently apply the routing table, you should use a persistent static route.<\/p>\n<p>Whether you&#8217;re managing a <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-dedicated-server-hosting\/\">dedicated server<\/a>, a <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-vps-hosting\/\">VPS server<\/a>, or a <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-cloud-hosting\/\">cloud hosting<\/a> environment, these skills will prove invaluable. For more in-depth tutorials and guides, be sure to explore other topics on our <a href=\"https:\/\/webhostinggeeks.com\/best\/web-server\/\">best web servers<\/a> page.<\/p>\n<h2>FAQs<\/h2>\n<ol itemscope itemtype=\"https:\/\/schema.org\/FAQPage\">\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is a static route?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">A static route is a manually configured network route that is used by the network layer protocols of a host&#8217;s operating system to determine where to send packets for a specific network destination.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is a default gateway?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">A default gateway is a device that forwards traffic from the local subnet to devices on other subnets. It serves as the forwarding host (router) for traffic that is addressed to a different subnet.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is the differencebetween a static route and a default gateway?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">A static route is a pre-determined path that network information must follow to reach a specific host or network, while a default gateway is a device that serves as an access point to another network.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is the &#8216;route&#8217; command in Linux?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The &#8216;route&#8217; command in Linux is used to show or modify the IP routing table. It allows you to add, delete, or display routes.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is the &#8216;netstat -rn&#8217; command in Linux?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The &#8216;netstat -rn&#8217; command in Linux is used to display the kernel routing table in numeric format. It&#8217;s a useful command for checking your network configuration and setting up a computer on a network.<\/span>\n            <\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In server administration, understanding how to manage static routes is a crucial skill. This guide will walk you through the process of adding static routes in CentOS 5.6, a popular&#8230;<\/p>\n","protected":false},"author":6,"featured_media":349,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1059],"tags":[1247,2089,1536,1802],"class_list":["post-1315","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-static-route","tag-centos-5-6","tag-configuration","tag-linux","tag-static-routes"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/1315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=1315"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/1315\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/349"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=1315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=1315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=1315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}