Ubuntu – How to configure a static IP address, but DNS via DHCP

bootdhcpdnsnetworkingserver

I've configured a static IP address in file /etc/network/interfaces:

auto eth0
iface eth0 inet static
    address 10.152.187.122
    gateway 10.152.187.1
    netmask 255.255.255.0

But I'd like DNS to be configured automatically with DHCP. For example, if I run dhclient, it populates /etc/resolv.conf properly. But I would like this to run at startup, and I'm not sure where the proper way to set that up.

This is on the UbuntuĀ 12.04 (Precise Pangolin) cloud image.

Best Answer

With DHCP, you get the DNS nameserver addresses that the router gets when it gets an IP address from your internet service provider (ISP). You can use the DNS nameserver addresses the router has like this:

auto eth0
iface eth0 inet static
  address 10.152.187.122   
  netmask 255.255.255.0
  gateway 10.152.187.1
  dns-nameservers 10.152.187.1
Related Question