How To Set A Static IP And DNS In Ubuntu 14.04 or Later
This article details how to set a static IP and DNS in Ubuntu: version 14.04 and later no longer allow direct editing of /etc/resolv.conf directly.
Using something like “echo nameserver 184.108.40.206 >> resolv.conf” will work temporarily but will be overwritten as soon as the machine is rebooted or the networking service restarted.
You must now modify /etc/resolvconf/resolv.conf.d/head or /etc/resolvconf/resolv.conf.d/tail.
/etc/resolv.conf is written from:
- DNS set on interfaces
While any and all of these work, it is much simpler to set this in the interface config aong with a static IP:
Edit /etc/network/interfaces and change the following:
- Your network card may be referred to as eth0, eth1, ens32 etc.
- Change your dns-nameservers to whatever you want them to be – the above ones are google’s own.
- The IP addressing must also be tailored to whatever your home router is configured with.
- Leaving the dns-nameservers directive out will result in the DNS servers from your ISP or home router being used instead.
auto eth0 iface eth0 inet dhcp
auto eth0 iface eth0 inet static address 192.168.0.50 netmask 255.255.255.0 gateway 192.168.0.1 network 192.168.0.0 broadcast 192.168.0.255 dns-nameservers 220.127.116.11 18.104.22.168
Finally, restart your ethernet:
$ sudo service networking restart $ sudo ifdown eth0 $ sudo ifup eth0