# dhcpd and dnsmasq hostname resolution

## tpuzak

I'm running a router with hardened-dev-sources, shorewall, dnsmasq, and dhcp.  NAT forewarding, dhcp assignment, and dns works fine.  I can surf the web and ssh to external sources.  The only problem that I'm encountering comes with dns name resolution of the computers on my local network.  For example, from the router/firewall, I can ping a host machine with the IP address, but I can't ping it with the computer's hostname.  I've tried several things to fix this, and it looks like it should be working.  I'm using dhcpd to assign IP addresses, and dnsmasq to do the DNS forewarding.  I'm not using the dnsmasq dhcp server, and I'd prefer not to.  Here's the details of my situation.

dhcpd assigns my host the IP 10.10.10.150.

Here's the line from the host's /etc/conf.d/net file

```

dhcpcd_eth0="-Dh hostComp"

```

The -h option sends the host's hostname (given by hostComp) to the dhcp server.  This gets logged in the file /var/log/dhcp/dhcpd.leases.  Here's the contents of my host's lease in that file:

```

lease 10.10.10.150{

     starts 4 2005/03/10 00:49:16;

     ends 3 2005/03/16 00:49:16;

     binding state active;

     next binding state free;

     hardware ethernet 00:06:1b:de:a3:5d;

     uid "\001\000\006\033\336\243]";

     client-hostname "hostComp";

}

```

As you can see, the hostname properly gets logged, as specified by the dhcpcd -h option.

Next I've set the dhcpd.leases as the dhcp-leasefile in /etc/dnsmasq.conf

```

dhcp-leasefile=/var/lib/dhcp/dhcpd.leases

```

I think that this should work because the dnsmasq man page specifies that this file must be an "ISC dhcpd lease file and [is] parsed for leases which are then added to the DNS system if the have a hostname."

I've even varified that dnsmasq reads this file after a dhcp request is granted.  This excerpt is from /var/log/everything/current

```

Mar 9 19:49:16 [dhcpd] DHCPACK on 10.10.10.150 to 00:06:1b:de:a3:5d (hostComp) via eth1

Mar 9 19:49:16 [dnsmasq] reading /var/lib/dhcp/dhcp.leases

```

the log goes on with dnsmasq reading /etc/resolve.conf and stating the nameservers that it is using.

It seems like dnsmasq is reading the proper file, which contains the proper information.  But for some reason, "hostComp" is not included in the names, so I can't ping hostComp from the router by name e.g. with

 *Quote:*   

> 
> 
> ping -c 3 hostComp
> 
> 

 

I can however ping with the IP address 10.10.10.150.  

Does anyone know what I'm doing wrong?  How can I (finally) get these hostnames to be DNS accessable?

Thanks in advance.

-Tom

----------

## UberLord

The problem is that dnsmasq is an all-in-one solution for dhcp/dns - you can't easily split it up.

If you need to, you'll need software that integrates well with each other, for example dhcpd with bind/named

----------

## tpuzak

I don't think that's true.  Older versions of dnsmasq (before the intigrated dhcp server) did dhcp name resolution this way.  Also, the dnsmasq manpage specifies that if the --dhcp-leasefile option is set, and no dhcp-range is specified, then dnsmasq version 1 behavior is activated...which is exactly what I want.  So I think these should easily integrate.  Dnsmasq is clearly reading the dhcpd.leases file, it's just not cacheing the hostnames.

----------

## tpuzak

I did some checking and dnsmasq definately supports what I'm trying to do.  The functionality to read ISC's dhcpd.leases files was removed for a time but it was put back into the code in version 2.6.  I have 2.15 installed.  Here's an excerpt from the dnsmasq changelog:

 *Quote:*   

> 
> 
> Added back the ability to read ISC dhcpd lease files, by
> 
> 	     popular demand. Note that this is deprecated and for
> ...

 

I even checked the source code for dnsmasq, and this option is definately set.  From dnsmasq-2.15/src/config.h:

```

#define HAVE_ISC_READER

```

So I'm convinced that dnsmasq has the functionality that I want, and that it's reading my leases file (see first post), it's just not cacheing the hostnames that the clients provide.

Any ideas?

----------

## thebigslide

dnsmasq reads local dns info from /etc/hosts on the server if you're not using it's dhcp server.

Post your /etc/hosts

should be like

```

127.0.0.1 localhost  hostnameofrouter  hostnameofrouter.domain

ipaddress  hostname hostname.domain

etc.

```

----------

## tpuzak

from the dnsmasq manpage:

 *Quote:*   

> 
> 
>       -l, --dhcp-leasefile=<path>
> 
>               Use  the specified file to store DHCP lease information. If this
> ...

 

So if I have this specified, but am not using the dnsmasq dhcp server, then dnsmasq should get the dynamic hostnames from this file.  /etc/hosts won't work for me here because of the dynamic addresses.  That business about excluding this at compile time requires you to modify the source to undefine HAVE_ISC_READER.  So by default, dnsmasq will read a lease file even if you're not using its dhcp server.

----------

## thebigslide

The hostnames will always get the same IP if you setup the hostnames in the dhcpd.conf.

This is preferred if you want to do any routing or port forwarding as the same machines will always have the same IP.

----------

## MarkDavies

Has anybody had any success in getting dnsmasq and dhcpd to work together?

My setup sounds similar to tpuzak's. dhcpd serves out IPs. dnsmasq handles the cache of DNS queries. I've configured dnsmasq to read hdcpd's lease file and its trace indicates that it has read the file. I can't seem to ping machines on the network using hostnames, only IPs.

Could this problem be anything to do with domain names?

I've only every tried to ping machines on the network with hostnames rather than hostname.domainname

tpuzak, 

  could you post you dnsmasq and dhcpd conf files please. I'll compare them with mine when I get home and have chance to look into the problem.

  do you have the 'domain-needed' option in your dnsmasq.conf file?

Thanks,

 Mark.

----------

## thomateverte

Hi,

Resurecting this old thread...

Does any of you have a solution for this problem ? I have the same kind of setup and the same kind of problem. I cannot resolve names of the computers in the network. IPs work fine though...

----------

## keyser_soze

I use dnsmasq as a dns cache and dhcp and i can resolve both ips and names. it works from windows and linux.

You have to enable some options in the dnsmasq.conf file and make sure you have entries in /etc/hosts

here are the options i have enabled in dnsmasq.conf

```

domain-needed

bogus-priv

filterwin2k

local=/workgroup/

interface=eth1

expand-hosts

domain=workgroup

dhcp-range=192.168.2.50,192.168.2.100,12h

read-ethers

dhcp-authoritative

```

particularly you have to have 

local=/domainname you want/

expand-hosts

domain=domainname you want

dhcp-range=min,max,leastime

take out the read-ethers line if you dont use /etc/ethers file.

if you want to set some static ips you can make entries in /etc/ethers you can make it so that the ips in /etc/hosts are set statically to the mac addresses set in /etc/ethers using the examples below

here is an example /etc/hosts

```

127.0.0.1       localhost

192.168.1.1     computer1

192.168.1.2     computer2

....

```

here is an example /etc/ethers

```

00:14:55:04:87:E7       computer1

00:50:5D:A9:E7:D3      computer2

....

```

then computer2 will always be assigned 192.168.1.2 by the DHCP always.

dynamic addresses will be added as expected in the range given.

you can then ping computer1 and you will get back computer1.workgroup ... or whatever your domainname is.

hope this is what you are after

----------

## pjp

Split bdw's problem into a seperate thread.  This one is active.

----------

## UberLord

FWIW, I would recommend using bind + dhcp(d) OR dnsmasq

But don't mix the two  :Smile: 

I myself haved moved from dnsmasq to bind + dhcp as my needs have grown beyond the scope of dnsmasq.

----------

## John R. Graham

Actually, I think that the solution is simple and has been missed so far by those that have posted.  The dnsmasq program provides names resultion for all computers that have been told to use it via DHCP.  The computer you're running dnsmasq on cannot be told to use it via DHCP because it is normally fixed address, being the router.    :Smile: 

In order for the router to properly resolve names on itself, it needs to be mentioned in its own resolv.conf file, like so:

```
nameserver 127.0.0.1
```

I believe that this should be included first, before the IP addresses of your upstream name server(s).

Anyway, I had the exact same symptoms and played around endlessly with dnsmasq.conf before I realized that nobody had told localhost that localhost was a name server!

This simple change did it for me.  Also, it allows you to avoid all fixed addresses in your system except that of the router / name server itself, which I think is very desirable.  Incidentally, I use dnsmasq as both a DHCP server and DNS.  On my small home network, this works perfectly.

- John

----------

