{"id":32,"date":"2014-10-10T09:11:00","date_gmt":"2014-10-10T09:11:00","guid":{"rendered":"http:\/\/www.asianux.org.vn\/index.php\/2014\/10\/10\/how-to-set-a-default-gateway-on-centos-2\/"},"modified":"2014-10-10T09:11:00","modified_gmt":"2014-10-10T09:11:00","slug":"how-to-set-a-default-gateway-on-centos-2","status":"publish","type":"post","link":"https:\/\/www.asianux.org.vn\/index.php\/2014\/10\/10\/how-to-set-a-default-gateway-on-centos-2\/","title":{"rendered":"How to set a default gateway on CentOS"},"content":{"rendered":"<div style=\"-webkit-text-stroke-width: 0px; background-color: white; border: 0px; clear: none; color: #445263; font-family: Arial, Helvetica, sans-serif; font-size: 0.9em; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; margin: 0px 0px 10px; orphans: auto; outline: 0px; padding: 0px; text-align: start; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: auto; word-spacing: 0px;\"><span style=\"border: 0px; font-family: inherit; font-size: 14px; font-style: inherit; font-weight: inherit; margin: 0px 10px 0px 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><br \/><\/span><span style=\"border: 0px; display: inline-block; font-family: inherit; font-size: 14px; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\"><a href=\"http:\/\/xmodulo.com\/how-to-set-a-default-gateway-on-centos.html#comments\" style=\"border: 0px; color: #242448; font-family: inherit; font-size: 14px; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;\" title=\"Comment on How to set a default gateway on CentOS\" target=\"_blank\" rel=\"noopener\"><\/a><\/span><\/div>\n<div style=\"-webkit-text-stroke-width: 0px; background-color: white; border: 0px; color: #445263; font-family: Arial, Helvetica, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22.9500007629395px; margin: 0px; orphans: auto; outline: 0px; padding: 0px; text-align: start; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: auto; word-spacing: 0px;\">\n<div style=\"border: 0px; font-family: inherit; font-size: 15px; font-style: inherit; font-weight: inherit; margin: 0px 0px 0.9em; outline: 0px; padding: 0px; vertical-align: baseline;\">A default gateway is a remote host or router that your Linux host forwards traffic to when the destination IP address of outgoing traffic does not match any route in your local routing table. Configuring a default gateway on CentOS is quite straightforward.<\/div>\n<div style=\"border: 0px; font-family: inherit; font-size: 15px; font-style: inherit; font-weight: inherit; margin: 0px 0px 0.9em; outline: 0px; padding: 0px; vertical-align: baseline;\">If you wish to change a default gateway temporarily at run time, you can use<span>&nbsp;<\/span><tt style=\"border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">ip<\/tt><span>&nbsp;<\/span>command.<\/div>\n<div style=\"border: 0px; font-family: inherit; font-size: 15px; font-style: inherit; font-weight: inherit; margin: 0px 0px 0.9em; outline: 0px; padding: 0px; vertical-align: baseline;\">First things first. To check what default gateway you are using currently:<\/div>\n<div style=\"background: rgb(0, 153, 204); border: 0px none; color: white; font-family: monospace; font-size: 13px; font-style: inherit; font-weight: inherit; margin: 0px 0px 15px; outline: 0px; overflow: auto; padding: 5px; vertical-align: baseline; white-space: nowrap;\">$ ip route show<\/div>\n<pre style=\"background: rgb(238, 238, 238); border: 1px dashed rgb(204, 204, 204); margin: 0px 0px 15px; overflow: auto; padding: 10px;\">192.168.91.0\/24 dev eth0  proto kernel  scope link  src 192.168.91.128 <br \/>169.254.0.0\/16 dev eth0  scope link  metric 1002 <br \/><strong style=\"border: 0px; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">default via 192.168.91.2 dev eth0 <\/strong><br \/><\/pre>\n<div style=\"border: 0px; font-family: inherit; font-size: 15px; font-style: inherit; font-weight: inherit; margin: 0px 0px 0.9em; outline: 0px; padding: 0px; vertical-align: baseline;\">According to the local routing table shown above, a default gateway is 192.168.91.2, and traffic is forwarded to the gateway via eth0.<\/div>\n<div style=\"border: 0px; font-family: inherit; font-size: 15px; font-style: inherit; font-weight: inherit; margin: 0px 0px 0.9em; outline: 0px; padding: 0px; vertical-align: baseline;\"><strong style=\"border: 0px; font-family: inherit; font-size: 15px; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">In order to change a default gateway to another IP address<\/strong>:<\/div>\n<div style=\"background: rgb(0, 153, 204); border: 0px none; color: white; font-family: monospace; font-size: 13px; font-style: inherit; font-weight: inherit; margin: 0px 0px 15px; outline: 0px; overflow: auto; padding: 5px; vertical-align: baseline; white-space: nowrap;\">$ sudo ip route replace default via 192.168.91.10 dev eth0<\/div>\n<div style=\"border: 0px; font-family: inherit; font-size: 15px; font-style: inherit; font-weight: inherit; margin: 0px 0px 0.9em; outline: 0px; padding: 0px; vertical-align: baseline;\">Obviously, a default gateway&#8217;s IP address should come from the subnet associated with the interface connected to the default gateway, in this example, 192.168.91.0\/24. Otherwise, the command will fail with the following error.<\/div>\n<pre style=\"background: rgb(238, 238, 238); border: 1px dashed rgb(204, 204, 204); margin: 0px 0px 15px; overflow: auto; padding: 10px;\">RTNETLINK answers: No such process<br \/><\/pre>\n<div style=\"border: 0px; font-family: inherit; font-size: 15px; font-style: inherit; font-weight: inherit; margin: 0px 0px 0.9em; outline: 0px; padding: 0px; vertical-align: baseline;\">Also, keep in mind that the default route change made by<span>&nbsp;<\/span><tt style=\"border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">ip<\/tt><span>&nbsp;<\/span>command will be lost after rebooting.<\/div>\n<div style=\"border: 0px; font-family: inherit; font-size: 15px; font-style: inherit; font-weight: inherit; margin: 0px 0px 0.9em; outline: 0px; padding: 0px; vertical-align: baseline;\"><strong style=\"border: 0px; font-family: inherit; font-size: 15px; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">In order to set a default gateway permanently on CentOS<\/strong>, you will need to update \/etc\/sysconfig\/network accordingly.<\/div>\n<div style=\"background: rgb(0, 153, 204); border: 0px none; color: white; font-family: monospace; font-size: 13px; font-style: inherit; font-weight: inherit; margin: 0px 0px 15px; outline: 0px; overflow: auto; padding: 5px; vertical-align: baseline; white-space: nowrap;\">$ sudo vi \/etc\/sysconfig\/network<\/div>\n<pre style=\"background: rgb(238, 238, 238); border: 1px dashed rgb(204, 204, 204); margin: 0px 0px 15px; overflow: auto; padding: 10px;\">GATEWAY=192.168.91.10<br \/><\/pre>\n<div style=\"border: 0px; font-family: inherit; font-size: 15px; font-style: inherit; font-weight: inherit; margin: 0px 0px 0.9em; outline: 0px; padding: 0px; vertical-align: baseline;\">Again, be aware that the IP addressed specified here should match with the subnet (192.168.91.0\/24) associated with a default route interface.<\/div>\n<div style=\"border: 0px; font-family: inherit; font-size: 15px; font-style: inherit; font-weight: inherit; margin: 0px 0px 0.9em; outline: 0px; padding: 0px; vertical-align: baseline;\">Another option to set a default gateway persistently on CentOS is to edit \/etc\/sysconfig\/network-scripts\/ifcfg-&lt;default_interface_name&gt;, and add &#8220;GATEWAY=&lt;gateway_ip&gt;&#8221; there. If the default interface is &#8220;eth0&#8221;, you will need to edit \/etc\/sysconfig\/network-scripts\/ifcfg-eth0. If you choose to use this method, you need to refer to<span>&nbsp;<\/span><a href=\"http:\/\/xmodulo.com\/2013\/01\/how-to-configure-networking-in-centos-desktop-with-command-line.html\" style=\"border: 0px; color: #242448; font-family: inherit; font-size: 15px; font-style: inherit; font-weight: inhe\nrit; margin: 0px; outline: 0px; padding: 0px; text-decoration: underline; vertical-align: baseline;\" target=\"_blank\" rel=\"noopener\">this post<\/a><span>&nbsp;<\/span>to get familiar with this option.<\/div>\n<div style=\"border: 0px; font-family: inherit; font-size: 15px; font-style: inherit; font-weight: inherit; margin: 0px 0px 0.9em; outline: 0px; padding: 0px; vertical-align: baseline;\">Whether you edit \/etc\/sysconfig\/network or \/etc\/sysconfig\/network-scripts\/ifcfg-ethX, don&#8217;t forget to restart<span>&nbsp;<\/span><tt style=\"border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;\">network<\/tt>service as follows, or reboot your CentOS for the change to take effect.<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>A default gateway is a remote host or router that your Linux host forwards traffic to when the destination IP address of outgoing traffic does not match any route in your local routing table. Configuring&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-32","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/comments?post=32"}],"version-history":[{"count":0,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/32\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/media?parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/categories?post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/tags?post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}