{"id":1135,"date":"2018-11-23T14:38:13","date_gmt":"2018-11-23T05:38:13","guid":{"rendered":"https:\/\/manatails.net\/blog\/?p=1135"},"modified":"2022-04-03T13:48:53","modified_gmt":"2022-04-03T04:48:53","slug":"setting-primary-interface-in-ubuntu","status":"publish","type":"post","link":"https:\/\/manatails.net\/blog\/2018\/11\/setting-primary-interface-in-ubuntu\/","title":{"rendered":"Setting primary interface in ubuntu"},"content":{"rendered":"<p>Unlike CentOS, ubuntu doesn&#8217;t provide a nice tool to set default routes when there are more than 1 ethernet interfaces are connected at the same time. It is possible to set up a static route with post-up but it is still difficult to do if the DHCP range is dynamic and you can&#8217;t accurately determine the proper gateway.<\/p>\n<p>I was able to reliably implement it with the following settings.<br \/>\nOpen \/etc\/network\/interfaces file and<br \/>\nAdd the following line to all other interfaces that does NOT act as a default gateway.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">post-up route del default dev $IFACE<\/pre>\n<p>&nbsp;<\/p>\n<p>This code, instead of setting a default route, basically removes undesired default routes as the device goes up.<\/p>\n<p>Example configuration when you want to use ens160 as default route:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">auto ens172\r\niface ens172 inet dhcp\r\npost-up route del default dev $IFACE\r\n\r\nauto ens192\r\niface ens192 inet dhcp\r\npost-up route del default dev $IFACE\r\n\r\n# The primary network interface\r\nauto ens160\r\niface ens160 inet dhcp\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Unlike CentOS, ubuntu doesn&#8217;t provide a nice tool to set default routes when there are more than 1 ethernet interfaces are connected at the same time. It is possible to set up a static route with post-up but it is still difficult to do if the DHCP range is dynamic and you can&#8217;t accurately determine &hellip; <a href=\"https:\/\/manatails.net\/blog\/2018\/11\/setting-primary-interface-in-ubuntu\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Setting primary interface in ubuntu<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1135","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/manatails.net\/blog\/wp-json\/wp\/v2\/posts\/1135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/manatails.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/manatails.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/manatails.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/manatails.net\/blog\/wp-json\/wp\/v2\/comments?post=1135"}],"version-history":[{"count":6,"href":"https:\/\/manatails.net\/blog\/wp-json\/wp\/v2\/posts\/1135\/revisions"}],"predecessor-version":[{"id":1343,"href":"https:\/\/manatails.net\/blog\/wp-json\/wp\/v2\/posts\/1135\/revisions\/1343"}],"wp:attachment":[{"href":"https:\/\/manatails.net\/blog\/wp-json\/wp\/v2\/media?parent=1135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/manatails.net\/blog\/wp-json\/wp\/v2\/categories?post=1135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/manatails.net\/blog\/wp-json\/wp\/v2\/tags?post=1135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}