3

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.

  • @Peter If you edit in links, at least use up-to-date or generic links. For example, the Ubuntu manpages website supports links of the form: http://manpages.ubuntu.com/interfaces.5. – muru Jan 3 '15 at 2:59
2

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
  • This seems to work, except dhcp makes my resolv.conf also contain "search mydomain.com". And I wonder what else dhclient will do dynamically that this misses out on. – Ian Kelling Jan 2 '15 at 22:55
  • mydomain.com is a domain registrar. That simply gives another method to resolve names to numbers. – chili555 Jan 2 '15 at 23:09
  • mydomain.com was meant as an example. I hould have said something like example.of.a.domain – Ian Kelling Jan 3 '15 at 6:14
  • In any case, 'search anything.com' is simply another place to search in case the requested location is not found. Otherwise, you'd get a 'Webpage not available.' – chili555 Jan 3 '15 at 13:39
  • @IanKelling Simply add "dns-search mydomain.com" as well. – Emil Styrke Sep 18 '15 at 5:30
2

What you're asking for is essentially a hybrid configuration of static IP but DHCP DNS. There is no such type of network setup - you either have static, or DHCP.

You can explicitly define DNS nameservers, though, in your configuration, like so. This keeps static addresses, but unfortunately will not set DNS dynamically (which isn't really possible in a hybrid setup like this one).

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
  dns-nameservers 8.8.8.8
  dns-nameservers 8.8.4.4
  ...

TL;DR: There's no way to get DHCP DNS, Static IP, unless you have a static entry set in the DHCP assignments table at the router - which guarantees that you'll always get that IP because it's specifically already reserved for that specific system/MAC address

0

I'm also interested in querying DNS servers from DHCP without using other information.

Dhcpcd might allow to query it (dhcpcd -o domain_name_servers -T), but I couldn't find anything for dhclient.

Besides using a modified dhclient (see here on GitHub and here on Stack Overflow) or a test-client (as in this blog) or different scripts (see this on Stack Overflow) I found a powershell solution here on indented.co.uk.

This made me think of using "the basics" on Linux and I ended up with a crafted dhcp-request using printf.

Some fields may be bogus (like mac aa:bb:cc:dd:ee:ff) but it contains options 53=0x35 (len 1 / value 1 = Request) and 55=0x37 (len 1 / value 6 for DNS).

For broadcasting socat is used:

printf "\x1\x1\x6\x0\xd3\x44\x33\xeb\x0\x0\x80\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\xaa\xbb\xcc\xdd\xee\xff\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x63\x82\x53\x63\x35\x01\x01\x37\x01\x06\xff" |  socat - UDP4-DATAGRAM:255.255.255.255:67,broadcast

Simliar socat is used for receiving an reply

socat -u udp-recv:68,reuseaddr -

or

socat -u udp-recv:68 - | dd bs=1 skip=$( printf "%d" 0xec )

Using xxd I found what I was looking for...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.