This is all on a LAN:

  • I have a bunch of Linux machines (I'm calling these endpoints) which receive their IPs from a DHCP server that I don't control.
  • I don't control our internal DNS
  • However, I do control an Ubuntu server with a static IP and known name: ubuntu.domain.com

I want to be able to access these machines by their hostnames, or hostname.ubuntu.domain.com.

Either I need to notify our DNS server about these hostnames, figure out what name resolution services are available already (pinging Windows or Linux hostnames both resolve to an opendns IP which is wrong), configure a service like dnsmasq, or use a dynamic DNS website (not ideal for this mostly closed network)

With dnsmasq it looks like I need to set each machine to obtain an IP from ubuntu.domain.com. I don't want to do this. I must maintain the current DHCP situation. Someone would be mad if our DHCP requests went through my own machine.

Is it possible to forward DHCP requests from dnsmasq to my default DHCP provider?

Somehow each machine needs to notify ubuntu.domain.com of its (hostname, IP) pair.

I want to avoid modifying anything but the named endpoints to use to ubuntu.domain.com as a DNS source, which is why the hostname.ubuntu.domain.com scheme seems good. I don't know if this is even possible, though.

TLDR: How do I resolve Linux hostnames easily?


You can choose to get your IP address from DHCP as you do now, but override the DNS servers so that they point to ubuntu.domain.com

Then install bind on ubuntu.domain.com and set up a zone for ubuntu.domain.com that accepts registrations from the local network. Set up bind on ubuntu.domain.com so that it forwards any DNS request for zones it is not authoritative for to the current DNS servers.

To override the name servers edit /etc/dhclient.conf and add

supersede domain-name-servers <ubuntu server ip>;

To register the hostname of the PC to the DNS server, also add:

supersede domain-name "ubuntu.domain.com";
send host-name "hostname.ubuntu.domain.com";

To permit zone registrations in bind on ubuntu.domain.com add this to the options section in /etc/bind/named.conf.options. Also add the forwarders for non-authoritative zones:

options {
    allow-update { <your network>/<your subnet mask> (eg; };
    forwarders { <current dns server>; <current dns server>; };

Then you'll need to define the zone in /etc/bind/named.conf.local:

zone "ubuntu.domain.com" {
    type master;
    file "/etc/bind/pri/db.ubuntu.domain.com";

The zone file /etc/bind/pri/db.ubuntu.domain.com will look like this

$TTL 604800     ; 1 week
ubuntu.domain.com      IN SOA  ubuntu.domain.com. dns.ubuntu.domain.com. (
                            260        ; serial
                            604800     ; refresh (1 week)
                            86400      ; retry (1 day)
                            2419200    ; expire (4 weeks)
                            604800     ; minimum (1 week)
                    NS      ubuntu.domain.com.
                    A       <ip address of ubuntu.domain.com>

The additional A records for registing hosts will be added to this file.

So the sequence is

  1. dhclient will request an IP from the current DHCP server
  2. dhcp server responds with IP, gateway and DNS
  3. dhclient accepts IP and gateway, and overrides dns with ubuntu.domain.com
  4. dhclient registers its hostname with ubuntu.domain.com dns
  5. DNS queries go to ubuntu.domain.com - if they are within ubuntu.domain.com zone, it will resolve locally, otherwise forward to the current DNS servers
  • Thank you. If I want a lookup from a machine which cannot have its network settings modified, I suppose I can use nslookup hostname ubuntu.domain.com.
    – Cat
    Dec 16 '11 at 0:32
  • @Cat Yeah, thats it, I can't see a way you can get this to work automatically without having root access.
    – Paul
    Dec 16 '11 at 0:52

If you want to resolve the names from any address the best thing to do is get them into DNS. Often the DHCP server will register the name your host uses when it asks for an IP address. In most cases this should be an unqualified hostname. This is often disabled in the DHCP client configuration. It should then appear in a location which can be resolved using the searchlist provided by DHCP.

DNSMasq can be configured to use the DNS servers provided by DHCP. I believe the default configuration on Ubuntu will handle the configuration automatically.

The names you use should fit in the DNS hierarchy of the organization you work with.

For servers you need to be able to access remotely, the preferred solution is to use a static IP address. This would require co-ordination with the network and DNS administrators.

EDIT: If you have work without the support of the administrators you can build a /etc/hosts file on one server and use dnsmasq as the primary DNS server for all the servers that need to co-ordinate. The /etc/hosts file should work as your DHCP will likely give you effectively static addresses.

If your IP addresses are dynamic, you may need to setup a mechanism for the hosts to register IP address changes. The DHCP client has hooks for this. The trick will be discovering where to register when IP addresses change. Notifying the clients (other servers) may be the simplest solution. The processes doing this can be unprivileged (non-root). If so, then dnsmasq should be configured with an alternate hosts file.

Another alternative would be to use avahi to allow the servers to discover each others. It can be configured for domains other than local.

  • I can't get names into DNS for the near future, and static IP addresses are also not an option. I can't work with my organization, so I must do this by routing through a box I control.
    – Cat
    Dec 16 '11 at 0:27

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.