How do I configure dnsmasq to resolve local hostnames with dualstack ipv4 & ipv6?

3

1

Problem: I have a router (openwrt) at home and I want computers to connect to each other on the local subnet by simply typing hostname instead of their ip. Right now when dns query is send to router, router responds with only ipv4 address (without ipv6 address). I want router responding with both ipv4 and ipv6 addresses.

Scenario: I have router with openwrt installed - CHAOS CALMER (15.05.1, r48532). For ipv4 I have subnet 192.168.1.0/24. All computers on lan can talk/connect to each other. If they want to connect to internet (e.g. google.com) they go through NAT on router. Basic configuration. For ipv6 I created ULA prefix (with some generator) and configured it through web interface (luci). I have no internet (from ISP) with ipv6, so all communication is limited to local computers.

What works:
* computers can obtain both ipv4 and ipv6 ip from router
* computers can communicate to each other through both ipv4 and ipv6 (e.g. ping, ping6 or ssh -4, ssh -6)
* computers can ask dns server on router for google.com and get both ipv4 and ipv6 addresses
* computers can ask dns server on router for hostname of another computer and only get ipv4 address
* I can set static hostname (through luci) to ipv6 address and when computers on lan ask about it, they get ipv6 address correctly

I can't get working hostname resolution for ipv6 addresses, which seems weird to me, because for ipv4 it works perfectly.

How do I configure dnsmasq to resolve local hostnames with both ipv4 AND ipv6?


/etc/config/dhcp

config dnsmasq                      
        option localise_queries '1'        
        option rebind_protection '1'
        option rebind_localhost '1'        
        option authoritative '1'                 
        option readethers '1'                    
        option leasefile '/tmp/dhcp.leases'       
        option noresolv '1'                       
        list server '127.0.0.1#5353' # <-- I am using dnscrypt
        list server '/pool.ntp.org/2620:0:ccc::2' 
        list server '/pool.ntp.org/2620:0:ccd::2' 
        list server '/pool.ntp.org/208.67.222.222'
        list server '/pool.ntp.org/208.67.220.220'
        option local '/home/'  
        option domain 'home'   
        option nonegcache '1' 
        option domainneeded '1'
        option boguspriv '1'  

config dhcp 'lan'         
        option interface 'lan'
        option start '100'    
        option limit '150'   
        option leasetime '12h'  
        option force '1'      
        option ra 'server'      
        option dhcpv6 'server'  
        option ra_default '1'
        option ra_management '1'

config dhcp 'wan'          
        option interface 'wan'              
        option ignore '1'                            

config odhcpd 'odhcpd'                               
        option maindhcp '0'                          
        option leasefile '/tmp/hosts/odhcpd'         
        option leasetrigger '/usr/sbin/odhcpd-update'

dnsmasq --version

Dnsmasq version 2.73  Copyright (c) 2000-2015 Simon Kelley
Compile time options: IPv6 GNU-getopt no-DBus no-i18n no-IDN DHCP DHCPv6 no-Lua TFTP no-conntrack no-ipset no-auth no-DNSSEC loop-detect inotify

This software comes with ABSOLUTELY NO WARRANTY.
Dnsmasq is free software, and you are welcome to redistribute it
under the terms of the GNU General Public License, version 2 or 3.

opkg list-installed

base-files - 157.2-r48532
busybox - 1.23.2-1
bzip2 - 1.0.6-2
ca-certificates - 20150426
ddns-scripts - 2.4.3-2
dnscrypt-proxy - 1.4.3-1
dnsmasq-dhcpv6 - 2.73-1
dropbear - 2015.67-1
firewall - 2015-07-27
fstools - 2016-01-10-96415afecef35766332067f4205ef3b2c7561d21
hostapd-common - 2015-03-25-1
ip6tables - 1.4.21-1
iptables - 1.4.21-1
iw - 3.17-1
jshn - 2015-11-08-10429bccd0dc5d204635e110a7a8fae7b80d16cb
jsonfilter - 2014-06-19-cdc760c58077f44fc40adbbe41e1556a67c1b9a9
kernel - 3.18.23-1-dbb19f09b72b69f418ee332a4882bbad
kmod-cfg80211 - 3.18.23+2015-03-09-3
kmod-crypto-aes - 3.18.23-1
kmod-crypto-arc4 - 3.18.23-1
kmod-crypto-core - 3.18.23-1
kmod-eeprom-93cx6 - 3.18.23-1
kmod-gpio-button-hotplug - 3.18.23-1
kmod-ip6tables - 3.18.23-1
kmod-ipt-conntrack - 3.18.23-1
kmod-ipt-core - 3.18.23-1
kmod-ipt-nat - 3.18.23-1
kmod-ipv6 - 3.18.23-1
kmod-leds-gpio - 3.18.23-1
kmod-lib-crc-ccitt - 3.18.23-1
kmod-lib-crc-itu-t - 3.18.23-1
kmod-mac80211 - 3.18.23+2015-03-09-3
kmod-nf-conntrack - 3.18.23-1
kmod-nf-conntrack6 - 3.18.23-1
kmod-nf-ipt - 3.18.23-1
kmod-nf-ipt6 - 3.18.23-1
kmod-nf-nat - 3.18.23-1
kmod-nf-nathelper - 3.18.23-1
kmod-nls-base - 3.18.23-1
kmod-ppp - 3.18.23-1
kmod-pppoe - 3.18.23-1
kmod-pppox - 3.18.23-1
kmod-rt2800-lib - 3.18.23+2015-03-09-3
kmod-rt2800-mmio - 3.18.23+2015-03-09-3
kmod-rt2800-pci - 3.18.23+2015-03-09-3
kmod-rt2800-soc - 3.18.23+2015-03-09-3
kmod-rt2x00-lib - 3.18.23+2015-03-09-3
kmod-rt2x00-mmio - 3.18.23+2015-03-09-3
kmod-rt2x00-pci - 3.18.23+2015-03-09-3
kmod-slhc - 3.18.23-1
kmod-usb-core - 3.18.23-1
kmod-usb-ohci - 3.18.23-1
kmod-usb2 - 3.18.23-1
libacl - 20140812-1
libattr - 20150220-1
libblobmsg-json - 2015-11-08-10429bccd0dc5d204635e110a7a8fae7b80d16cb
libbz2 - 1.0.6-2
libc - 0.9.33.2-1
libgcc - 4.8-linaro-1
libip4tc - 1.4.21-1
libip6tc - 1.4.21-1
libiwinfo - 2015-06-01-ade8b1b299cbd5748db1acf80dd3e9f567938371
libiwinfo-lua - 2015-06-01-ade8b1b299cbd5748db1acf80dd3e9f567938371
libjson-c - 0.12-1
libjson-script - 2015-11-08-10429bccd0dc5d204635e110a7a8fae7b80d16cb
liblua - 5.1.5-1
libnl-tiny - 0.1-4
libopenssl - 1.0.2g-1
libpcre - 8.38-1
libpolarssl - 1.3.14-1
libpthread - 0.9.33.2-1
librt - 0.9.33.2-1
libsodium - 1.0.2-1
libubox - 2015-11-08-10429bccd0dc5d204635e110a7a8fae7b80d16cb
libubus - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
libubus-lua - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
libuci - 2015-08-27.1-1
libuci-lua - 2015-08-27.1-1
libustream-polarssl - 2015-07-09-c2d73c22618e8ee444e8d346695eca908ecb72d3
libxtables - 1.4.21-1
lua - 5.1.5-1
luci - git-16.018.33482-3201903-1
luci-app-ddns - 2.2.4-1
luci-app-firewall - git-16.018.33482-3201903-1
luci-base - git-16.018.33482-3201903-1
luci-lib-ip - git-16.018.33482-3201903-1
luci-lib-nixio - git-16.018.33482-3201903-1
luci-mod-admin-full - git-16.018.33482-3201903-1
luci-proto-ipv6 - git-16.018.33482-3201903-1
luci-proto-ppp - git-16.018.33482-3201903-1
luci-ssl - git-16.018.33482-3201903-1
luci-theme-bootstrap - git-16.018.33482-3201903-1
mtd - 21
netifd - 2015-12-16-245527193e90906451be35c2b8e972b8712ea6ab
odhcp6c - 2015-07-13-024525798c5f6aba3af9b2ef7b3af2f3c14f1db8
odhcpd - 2015-11-19-01d3f9d64486ac1daa144848944e877e7f0cb762
openssl-util - 1.0.2g-1
opkg - 9c97d5ecd795709c8584e972bfdf3aee3a5b846d-9
ppp - 2.4.7-6
ppp-mod-pppoe - 2.4.7-6
procd - 2015-10-29.1-d5fddd91b966424bb63e943e789704d52382cc18
px5g - 3
rpcd - 2015-01-10-f00890cd6eb47ad9bb5da0fb6c50aedc8406e7c5
swconfig - 10
tar - 1.28-2
ubox - 2015-11-22-c086167a0154745c677f8730a336ea9cf7d71031
ubus - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
ubusd - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
uci - 2015-08-27.1-1
uhttpd - 2015-11-08-fe01ef3f52adae9da38ef47926cd50974af5d6b7
uhttpd-mod-ubus - 2015-11-08-fe01ef3f52adae9da38ef47926cd50974af5d6b7
usign - 2015-05-08-cf8dcdb8a4e874c77f3e9a8e9b643e8c17b19131
wget - 1.17.1-1
wpad-mini - 2015-03-25-1
zlib - 1.2.8-1

kotoko

Posted 2017-09-09T13:49:58.957

Reputation: 33

Answers

0

If you don’t use a custom OpenWrt image, the default DHCP/DNS constellation is as follows:

  • dnsmasq does DHCPv4 and DNS
  • dnsmasq ships without DHCPv6 support (dunno why that’s different for you)
  • odhcpd does DHCPv6
  • dnsmasq does not interface with odhcpd in any way

So that’s why you only get IPv4 addresses.

It appears odhcpd creates a file in /etc/hosts format at /tmp/hosts/odhcpd (or whatever is set up in /etc/config/dhcp in the odhcpd section). For this to work, you need to set option dhcpv6 server in /etc/config/dhcp.

You could make dnsmasq use this file by making one of the following configuration changes:

  • In /etc/config/dhcp in the dnsmasq section add list addnhosts /tmp/hosts/odhcpd
  • In /etc/dnsmasq.conf add addn-hosts=/tmp/hosts/odhcpd

After adding those entries and restarting dnsmasq (/etc/init.d/dnsmasq restart), dnsmasq correctly responds with both IPv4 and IPv6 addresses. You gain no advantage though.

Also note that clients that don’t use DHCPv6 but just stateless autoconfiguration won’t appear with their IPv6 address.

Daniel B

Posted 2017-09-09T13:49:58.957

Reputation: 40 502

I added list addnhosts /tmp/hosts/odhcpd and then it was almost working - nslookup hostname on router showed ipv6 address, but on other computers did not. I had to remove lines option local '/home/' and option domain 'home' and then started working perfectly. – kotoko – 2017-09-09T18:25:04.163