68

I am using Ubuntu 12.04.

My /etc/network/interfaces file consists of:

# The loopback network interface  
auto lo  
iface lo inet loopback  


# The primary network interface  
auto eth0 
iface eth0 inet static  
address 192.168.1.58  
gateway 192.168.1.1
network 192.168.1.0  
broadcast 192.168.1.255
dns-nameservers 66.212.63.228 66.212.48.10  

I ran the command: /etc/init.d/networking restart

Which responded with:

*Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces  
*Reconfiguring network interfaces...  
RTNETLINK answers: File exists  
Failed to bring up eth0  
[ OK ]  

Next I ran ping google.com and received:

ping: unknown host google.com

I am not sure if my interfaces refreshed. How do I properly configure my network with my static DNS addresses?

jokerdino
  • 41,732

13 Answers13

30

As the questioner gives the contents of his /etc/network/interfaces I infer that he is using ifup to configure interfaces. But since he may actually be using NetworkManager, I will discuss that as well.

If you are using ifup then DNS settings go in /etc/network/interfaces. For each interface you add dns-* options appropriate for the nameserver(s) available over that interface. E.g., if a nameserver at address 1.2.3.4 is available over interface eth0, then add dns-nameservers 1.2.3.4 to the iface eth0 stanza.

If you are using NetworkManager then settings are entered in the Connection Editor (network indicator | Edit Connections...) in the IPv4 Settings tab.

Doing /etc/init.d/networking restart to reconfigure interfaces is deprecated. If you are using ifup then first ifdown each active network interface, then ifup each interface. If you are using NetworkManager then, first, disable networking using the indicator (top of the desktop); then open a terminal and run

sudo /etc/init.d/network-manager restart

and then enable networking using the indicator.

Or you can just reboot.

Regarding the fact that /etc/init.d/networking restart resulted in

RTNETLINK answers: File exists
Failed to bring up eth0  

This means that ifupdown thinks that eth0 is already up. Use ifdown --force eth0 to cause ifupdown to stop believing that it has already configured the interface.

Regarding the "deprecated" message, this message is no longer printed in Ubuntu 12.10 but you should still note that initscripts are "on their way out". To restart a service foo, use service foo restart or restart foo. Note also that if you want to reconfigure your interfaces it is better to ifdown them one by one than to rely on restarting "networking".

Owl
  • 634
jdthood
  • 12,625
20

If none of the above work, keep it mind that Ubuntu appends a tail file to the resolv.conf file that it generates.

Try this:

sudo mkdir -p /etc/resolvconf/resolv.conf.d
sudo nano /etc/resolvconf/resolv.conf.d/tail

Which will open a blank resolv.conf.d file in the nano text editor. You will need to place your DNS server address on the first line of this file and remember to end the line with a carriage return (hit enter) as seen below:

nameserver 10.20.1.2
  • You can also use Google's public DNS: 8.8.8.8 and/or 8.8.4.4.

Editing the tail file instead of the actual resolv.conf file will prevent your change from being lost upon a system reboot.

You will need to run sudo resolvconf -u to activate the change. You should be able to ping google.com after this. Good luck!

If the command above does not find resolvconf, you can download it using:

sudo apt install resolvconf
15

All of the answers which relate to /etc/network/interfaces incorrectly state dns-nameservers rather than dns-nameserver - below should work:

auto wlan0
iface wlan0 inet static
address 192.168.1.28
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameserver 8.8.8.8
dns-nameserver 8.8.4.4
dns-search something.network.com

(tested on Ubuntu 15.04)

babelmonk
  • 909
11

Command line version:

You should add your nameserver(s) to /etc/resolvconf/resolv.conf.d/base file this way:

nameserver 66.212.63.228 
nameserver 66.212.48.10
muru
  • 207,228
pl1nk
  • 6,667
6

Easiest method of configuring your DNS servers is to use NetworkManager

Under IPv4, fill in your dns server(s)

enter image description here

Panther
  • 104,528
5

I was able to work around this on a headless ubuntu server install by adding

nameserver 8.8.8.8

...after the relevant interface stuff in /etc/network/interfaces:

auto wlan0
iface wlan0 inet static
address 192.168.1.28
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8
dns-nameservers 8.8.4.4

Hope this helps later users!

corq
  • 86
4

Note: carefull using without direct access on the machine, this will cut the connection...

I use

sudo ifdown eth0

then

sudo ifup eth0

It will reset and release everything...

If it faces with errors related to configuration, you can use:

sudo ifdown eth0 --force
4

This worked for me

sudo vi /etc/resolvconf/resolv.conf.d/base

and add:

nameserver <add your router ip>

Run:

sudo resolvconf -u

I use core install of ubuntu server.

muru
  • 207,228
Bongo
  • 41
2

I had this problem. I thought i was going mad. Everytime i edited /etc/resolv.conf, it deleted my config. Turns out some total lunatic has distributed debian with network-manager, which is overwriting all my network settings.

This is how i fixed it:

1) sudo apt-get purge network-manager

This gets rid of this horrendous new tool that stops all the configs from working properly.

2) Edit the /etc/network/interfaces file:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

auto enp0s25
iface enp0s25 inet static
        address 192.168.1.2
        netmask 255.255.255.0
        gateway 192.168.1.1

3) Edit /etc/resolv.conf:

nameserver 8.8.8.8
nameserver 8.8.4.4

4) Reboot.

Congrats, you now have sane configs that work again.

Owl
  • 634
2

You are missing a subnet specification in the interfaces file.

Add netmask 255.255.255.0 to /etc/network/interfaces below the network line.

jdthood
  • 12,625
Brian
  • 29
1

For some reason the dns-nameservers statement does nothing in my case. And the other answers are not by the book, as they bypass dnsmasq as it is utilized in Ubuntu.

To do this right, edit /etc/dnsmasq.conf

Add your nameservers to the bottom of the file:

server=8.8.8.8
server=8.8.4.4

Restart dnsmasq to use the new settings: sudo service dnsmasq restart

Credit: https://unix.stackexchange.com/a/163506/187949

DustWolf
  • 439
0

Most distro you can setup your DNS SERVER over the path

nano /etc/resolv.conf

and setup inside for ex [mine is like as follow]:

nameserver 192.168.43.1
nameserver 8.8.8.8
nameserver 8.8.8.4
PYK
  • 321
0

You might configure that interface in an other file too, since you have more gateways.

Details are here.

antivirtel
  • 3,685