Can't set DNS with Static IP

24,145

When you do not want to use DHCP and/or want NetworkManager to ignore some interface that you want to manage manually, just provide a configuration via /etc/network/interfaces. The interface will then be ignored by NetworkManager. See

$ man interfaces

for further info on how to configure interfaces manually. This is a template file (snippet) that configures the interface eth0:

auto eth0
iface eth0 inet static
  address 192.168.0.10
  netmask 255.255.255.0
  gateway 192.168.0.1
  dns-nameservers 8.8.8.8

Obviously you need to change the IP addresses. Note that the last line is evaluated by resolconf (it's a package/program, I don't mean the resolv.conf file), when and only when the interface is brought up successfully. You can check if the interface is up with /sbin/ifconfig. That should output the keyword UP and the IP somewhere. gateway in the above snippet denotes the IP of your router. Check if this ip appears in your route with the command route -n. Then ping your router. If that works, then you could ping 8.8.8.8. If that works check if the DNS correctly appears in the /etc/resolv.conf file. If it does, then check if you can resolve DNS names. In that order. If something in betweens fails, it is not a problem with your DNS.

If you're not able to get this straight using /etc/network/interfaces (package ifupdown) and want to know how to bring up an interface with basic commands, drop a comment.

Then you need to investigate how the trouble started in the first place. You've learnt already that you first need to clarify that your machine is able to ping 8.8.8.8 before you conclude to an error at resolving DNS though that server. If all that works fine, but the resolver entry just doesn't get tranfered correctly from /etc/network/interfaces to /etc/resolv.conf then continue your research at the documentation of the package resolvconf.

CONCLUSION:

Do not deinstall your dhcp software, when you depend on the internet connection and have few experiences on how to configure an interface manually. There are a lot of high level packages involved with bringing up an interface, namely network-manager, ifupdown and resolvconf and others. Which one does what is not obvious. ;)

Share:
24,145

Related videos on Youtube

Clob
Author by

Clob

Updated on September 18, 2022

Comments

  • Clob
    Clob over 1 year

    I'm running Ubuntu 13.04.

    I uninstalled DHCP.

    I set my IP address to 192.168.1.200 and it's working just fine. I can connect to it via my other internet network machines.

    However, I've tried to set DNS in /etc/network/interfaces to:

    dns-nameservers 8.8.8.8 8.8.4.4
    

    And that doesn't work. I tried the prepend before it also.

    I tried the resolve.conf and resolve.conf.d/head and tail with nameserver 8.8.8.8 and that doesn't work.

    I restart each of the services each time I edit them and try to resolve an address and I get the typical unknown host www.google.com. I've restarted the VM too (it's set to bridged in VirtualBox).

    I can't re-install DHCP from repositories because DNS isn't working.

    Can someone please help me? I'm getting pretty frustrated. I've tried every solution I can find on google.

    • Clob
      Clob over 10 years
      When trying to ping 8.8.8.8 I get "Connect: Network is unreachable"
    • Admin
      Admin about 10 years
      The dns-nameservers option mentioned in the previous post works. But this option is not mentioned in the helpfile "man interfaces" which is ackward. I think it should be possible in KDE to configure a static IP with all parameters in system settings -> network settings, but this option is not available in KDE.
  • Clob
    Clob over 10 years
    Well, the internet connection was working fine before I removed DHCP in bridged mode. My mistake was removing DHCP instead of understanding how to set the static IP around it. I restored a backup and undid my mistake. Thanks though!