Erratic Local Hostname Resolution With Dnsmasq

Home » CentOS » Erratic Local Hostname Resolution With Dnsmasq
CentOS 2 Comments

Hi,

My local server is running CentOS 7. The machine has two NICs and is acting as a gateway. For DHCP and DNS, I’m using Dnsmasq. I have a strange little problem with local hostname resolution. Before going into more details, here’s my configuration.

[root@nestor:~] # ifconfig enp2s0: flags=4163 mtu 1500
inet 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255
ether 2c:27:d7:15:54:a1 txqueuelen 1000 (Ethernet)
RX packets 17122 bytes 17596130 (16.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 13426 bytes 2144915 (2.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 18 memory 0xfe8e0000-fe900000

enp3s0: flags=4163 mtu 1500
inet 192.168.2.1 netmask 255.255.255.0 broadcast 192.168.2.255
ether 00:22:64:8a:4c:c2 txqueuelen 1000 (Ethernet)
RX packets 6597320 bytes 9692134059 (9.0 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 534283 bytes 57365155 (54.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0xfe9e0000-fea00000

[root@nestor:~] # cat /etc/hostname nestor

[root@nestor:~] # cat /etc/hosts
# /etc/hosts
127.0.0.1 localhost.localdomain localhost
192.168.2.1 nestor.microlinux.lan nestor
192.168.2.252 hp-officejet.microlinux.lan hp-officejet
192.168.2.253 nas.microlinux.lan nas
192.168.2.254 wifi.microlinux.lan wifi

[root@nestor:~] # cat /etc/resolv.conf
# /etc/resolv.conf nameserver 127.0.0.1

[root@nestor:~] # cat /etc/dnsmasq.conf
# /etc/dnsmasq.conf domain-needed bogus-priv interface=enp3s0
dhcp-range=192.168.2.100,192.168.2.200,24h local=/microlinux.lan/
domain=microlinux.lan expand-hosts
# Cloudflare server=1.1.1.1
server=1.0.0.1
# Google
#server=8.8.8.8
#server=8.8.4.4
no-resolv
# Google dhcp-host=D4:85:64:B2:B2:1B,alphamule,192.168.2.2
dhcp-host=00:1E:C9:43:A7:BF,bernadette,192.168.2.3
dhcp-host=00:1D:09:15:4A:D8,raymonde,192.168.2.4
dhcp-host=00:1E:C9:42:84:7B,amandine,192.168.2.5
dhcp-host=B8:CA:3A:D6:5A:43,1C:3E:84:32:7E:87,buzz,192.168.2.6
dhcp-host=90:E6:BA:CF:04:8F,64:70:02:9A:AC:93,balthazar,192.168.2.7
dhcp-host=08:00:27:00:00:01,CentOSbox,192.168.2.10
dhcp-host=08:00:27:00:00:02,susebox,192.168.2.11
dhcp-host=10:62:E5:D4:95:60,hp-officejet,192.168.2.252
dhcp-host=00:11:32:26:63:A5,nas,192.168.2.253

Now here’s the problem. Some of the hostname are correctly resolved, while others are not. Here’s what it looks like when invoked from the server.

[root@nestor:~] # host alphamule alphamule has address 192.168.2.2
[root@nestor:~] # host bernadette bernadette has address 192.168.2.3
[root@nestor:~] # host raymonde Host raymonde not found: 3(NXDOMAIN)
[root@nestor:~] # host amandine Host amandine not found: 3(NXDOMAIN)
[root@nestor:~] # host buzz
[root@nestor:~] # host balthazar balthazar has address 192.168.2.7
[root@nestor:~] # host CentOSbox Host CentOSbox not found: 3(NXDOMAIN)
[root@nestor:~] # host susebox Host susebox not found: 3(NXDOMAIN)
[root@nestor:~] # host hp-officejet hp-officejet has address 192.168.2.252
[root@nestor:~] # host nas nas has address 192.168.2.253

Of course I could add all these hosts to /etc/hosts, but as far as I
understand, this *should* work with the hosts appearing only in
/etc/dnsmasq.conf. Or have I overlooked something ? Any suggestions ?

Cheers & happy new year,

Niki


Microlinux – Solutions informatiques durables
7, place de l’église – 30730 Montpezat Site : https://www.microlinux.fr Blog : https://blog.microlinux.fr Mail : info@microlinux.fr Tél. : 04 66 63 10 32

2 thoughts on - Erratic Local Hostname Resolution With Dnsmasq

  • Le 02/01/2019 à 16:09, Nicolas Kovacs a écrit :

    From what this *looks like* after experimenting, Dnsmasq isn’t 100 %
    able to read hostnames from dnsmasq.conf, and if I want complete local resolution, I have to put each hostname – in long and short form – in the servers’ /etc/hosts file. In my case:

    [root@nestor:~] # cat /etc/hosts
    # /etc/hosts
    127.0.0.1 localhost.localdomain localhost
    192.168.2.1 nestor.microlinux.lan nestor
    192.168.2.2 alphamule.microlinux.lan alphamule
    192.168.2.3 bernadette.microlinux.lan bernadette
    192.168.2.4 raymonde.microlinux.lan raymonde
    192.168.2.5 amandine.microlinux.lan amandine
    192.168.2.6 buzz.microlinux.lan buzz
    192.168.2.7 balthazar.microlinux.lan balthazar
    192.168.2.10 CentOSbox.microlinux.lan CentOSbox
    192.168.2.11 susebox.microlinux.lan susebox
    192.168.2.252 hp-officejet.microlinux.lan hp-officejet
    192.168.2.253 nas.microlinux.lan nas
    192.168.2.254 wifi.microlinux.lan wifi

    In my case, this works perfectly, and I can resolve local hostnames on the server and on each client.

    So as far as I understand, the price to pay is only a small redundancy between /etc/dnsmasq.conf and /etc/hosts.

    Cheers,

    Niki


    Microlinux – Solutions informatiques durables
    7, place de l’église – 30730 Montpezat Site : https://www.microlinux.fr Blog : https://blog.microlinux.fr Mail : info@microlinux.fr Tél. : 04 66 63 10 32

  • Am 02.01.2019 um 16:09 schrieb Nicolas Kovacs :

    DHCP names are registered in DNS when the clients are “online” …