{"id":297,"date":"2015-03-16T18:38:23","date_gmt":"2015-03-16T10:38:23","guid":{"rendered":"http:\/\/heliang.net.cn\/?p=297"},"modified":"2015-03-16T18:38:23","modified_gmt":"2015-03-16T10:38:23","slug":"how-to-set-a-static-ip-to-ubuntu-14-04-server","status":"publish","type":"post","link":"https:\/\/www.heliang.net.cn\/?p=297","title":{"rendered":"How to Set a Static IP to Ubuntu 14.04 Server"},"content":{"rendered":"<p style=\"background: white\"><span style=\"color:#999999; font-family:Verdana; font-size:8pt\">BY MICHAEL CHINN, ON APRIL 28TH, 2014<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\"><strong>How to set a static IP in Ubuntu 14.04 server<\/strong><br \/>\n\t\t<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">By default the Ubuntu 14.04 server sets the interface to use DHCP, here&#8217;s how to set a static IP address.<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">Edit &#8220;\/etc\/network\/interfaces&#8221;.\u00a0 In this example set-up we&#8217;ll use 192.168.1.50 as our server IP address:<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">$sudo nano \/etc\/network\/interfaces<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">Find and comment the (default) DHCP entry.\u00a0 Your &#8220;interfaces&#8221; file should look like this:<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014-<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\"># This file describes the network interfaces available on your system<br \/># and how to activate them. For more information, see interfaces(5).<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\"># The loopback network interface<br \/>auto lo<br \/>iface lo inet loopback<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\"># The primary network interface<br \/>auto eth0<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\"># DHCP not needed<br \/># iface eth0 inet dhcp<br \/>iface eth0 inet static<br \/>address 192.168.1.50<br \/>netmask 255.255.255.0<br \/>network 192.168.1.0<br \/>broadcast 192.168.1.255<br \/>gateway 192.168.1.1<br \/>dns-nameservers 8.8.8.8<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014-<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">Save and exit.<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">$sudo nano \/etc\/resolv.conf<br \/>Add:<br \/>nameserver 192.168.1.1<br \/>nameserver 8.8.8.8<br \/>search mynetwork.local<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">Save and exit.<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">Edit \/etc\/hosts<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">$sudo nano \/etc\/hosts<br \/>Add:<br \/>192.168.1.50\u00a0\u00a0\u00a0\u00a0 u1404server.mynetwork.local\u00a0\u00a0\u00a0\u00a0\u00a0 u1404server<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">Save and exit:<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">Reload (start and stop) network<br \/>$sudo ifdown eth0 &amp;&amp; sudo ifup eth0<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">Note: There is a bug (feature?) in 14.04 where &#8220;service networking start|stop|restart&#8221; does nothing. This command\/script worked in 13.10\/13.04\/12.04, however it doesn&#8217;t work in 14.04.<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">To revert back to the 13.10 networking scripts go to:<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">https:\/\/github.com\/metral\/restore_networking<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">This will replace the 14.04 scripts with the one used in 13.10.<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">$sudo apt-get install git<br \/>$sudo git clone https:\/\/github.com\/metral\/restore_networking.git<br \/>$cd restore_networking\/<br \/>$sudo .\/restore_networking.sh<br \/>\n<\/span><\/p>\n<p style=\"background: white\"><span style=\"color:black; font-family:Verdana; font-size:10pt\">miguel@u1404server:~$ sudo service networking restart<br \/>networking stop\/waiting<br \/>networking start\/running<br \/>\n<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>BY MICHAEL CHINN, ON APRIL 28TH, 2014 How to set a stat [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[],"_links":{"self":[{"href":"https:\/\/www.heliang.net.cn\/index.php?rest_route=\/wp\/v2\/posts\/297"}],"collection":[{"href":"https:\/\/www.heliang.net.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.heliang.net.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.heliang.net.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.heliang.net.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=297"}],"version-history":[{"count":1,"href":"https:\/\/www.heliang.net.cn\/index.php?rest_route=\/wp\/v2\/posts\/297\/revisions"}],"predecessor-version":[{"id":298,"href":"https:\/\/www.heliang.net.cn\/index.php?rest_route=\/wp\/v2\/posts\/297\/revisions\/298"}],"wp:attachment":[{"href":"https:\/\/www.heliang.net.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.heliang.net.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.heliang.net.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}