Get DNS via DHCP

Hi there,

i am using an TP-Link-Router TL-WR710N which has an wan and lan-interface. In /etc/config/network i set the wan-interface to dhcp and i got a ip-address from the internet-router which is connected to the internet. So far so good.

But i got no dns at wan although i know the Internet-router provides dns too. My only option was to add 8.8.8.8 to resolve.conf but i want it dynamically with the dhcp. And i know the the dhcp-entry comes with a dns-entry.

You would add a DHCP Option 6 to the LAN DHCP config in the LuCI web GUI:

Or in /etc/config/dhcp

config dhcp 'lan'                                
        option interface 'lan' 
        option start '100'                 
        option limit '150'                       
        option leasetime '12h'             
        option dhcpv6 'server'                   
        option ra 'server'     
        option ra_management '1'
        list dhcp_option '6,8.8.8.8,8.8.4.4'
2 Likes

Ok, i think there is a missunderstanding. I meant at the wan-port. I will add it in the description.

Not necessary.

Yes, not necessary, but we tested it with an other device and the internet-router does it

uci show network; uci show dhcp; ifstatus wan; cat /tmp/resolv.conf.auto

opkg update
opkg install tcpdump
tcpdump -vni any udp port 67 &
killall -SIGUSR1 udhcpc
root@OpenWrt:~# ping google.de
^C
root@OpenWrt:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=121 time=37.998 ms
64 bytes from 8.8.8.8: seq=1 ttl=121 time=37.873 ms
^C
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 37.873/37.935/37.998 ms


root@OpenWrt:~# uci show network
network.loopback=interface
network.loopback.ifname='lo'
network.loopback.proto='static'
network.loopback.ipaddr='127.0.0.1'
network.loopback.netmask='255.0.0.0'
network.globals=globals
network.globals.ula_prefix='fd79:5cfa:0b89::/48'
network.lan=interface
network.lan.ifname='eth1'
network.lan.proto='static'
network.lan.ip6addr='fd01:6665::2e0:99ff:feff:1001/64'
network.lan.netmask='255.255.255.0'
network.lan.ipaddr='10.0.0.1'
network.wan=interface
network.wan.ifname='eth0'
network.wan.proto='dhcp'

root@OpenWrt:~# uci show dhcp
dhcp.@dnsmasq[0]=dnsmasq
dhcp.@dnsmasq[0].domainneeded='1'
dhcp.@dnsmasq[0].boguspriv='1'
dhcp.@dnsmasq[0].filterwin2k='0'
dhcp.@dnsmasq[0].localise_queries='1'
dhcp.@dnsmasq[0].rebind_protection='1'
dhcp.@dnsmasq[0].rebind_localhost='1'
dhcp.@dnsmasq[0].local='/lan/'
dhcp.@dnsmasq[0].domain='lan'
dhcp.@dnsmasq[0].expandhosts='1'
dhcp.@dnsmasq[0].nonegcache='0'
dhcp.@dnsmasq[0].authoritative='1'
dhcp.@dnsmasq[0].readethers='1'
dhcp.@dnsmasq[0].leasefile='/tmp/dhcp.leases'
dhcp.@dnsmasq[0].resolvfile='/tmp/resolv.conf.auto'
dhcp.@dnsmasq[0].nonwildcard='1'
dhcp.@dnsmasq[0].localservice='1'
dhcp.lan=dhcp
dhcp.lan.interface='lan'
dhcp.lan.start='100'
dhcp.lan.limit='150'
dhcp.lan.leasetime='12h'
dhcp.lan.dhcpv6='server'
dhcp.lan.ra='server'
dhcp.wan=dhcp
dhcp.wan.interface='wan'
dhcp.wan.ignore='1'
dhcp.odhcpd=odhcpd
dhcp.odhcpd.maindhcp='0'
dhcp.odhcpd.leasefile='/tmp/hosts/odhcpd'
dhcp.odhcpd.leasetrigger='/usr/sbin/odhcpd-update'
dhcp.odhcpd.loglevel='4'

root@OpenWrt:~# ifstatus wan
{
	"up": true,
	"pending": false,
	"available": true,
	"autostart": true,
	"dynamic": false,
	"uptime": 209,
	"l3_device": "eth0",
	"proto": "dhcp",
	"device": "eth0",
	"updated": [
		"addresses",
		"routes",
		"data"
	],
	"metric": 0,
	"dns_metric": 0,
	"delegation": true,
	"ipv4-address": [
		{
			"address": "192.168.6.221",
			"mask": 24
		}
	],
	"ipv6-address": [
		
	],
	"ipv6-prefix": [
		
	],
	"ipv6-prefix-assignment": [
		
	],
	"route": [
		{
			"target": "0.0.0.0",
			"mask": 0,
			"nexthop": "192.168.6.2",
			"source": "192.168.6.221\/32"
		}
	],
	"dns-server": [
		"192.168.6.2"
	],
	"dns-search": [
		"intern"
	],
	"inactive": {
		"ipv4-address": [
			
		],
		"ipv6-address": [
			
		],
		"route": [
			
		],
		"dns-server": [
			
		],
		"dns-search": [
			
		]
	},
	"data": {
		"leasetime": 30000
	}
}

root@OpenWrt:~# vi /etc/resolv.conf <-- added "nameserver 8.8.8.8" to install tcpdump
root@OpenWrt:~# ping google.de
PING google.de (216.58.210.3): 56 data bytes
64 bytes from 216.58.210.3: seq=0 ttl=55 time=34.766 ms
^C
--- google.de ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 34.766/34.766/34.766 ms

root@OpenWrt:~# tcpdump -vvvni any udp port 68 &
[1]-  Done(1)                    tcpdump --vvvni any udp port 68
root@OpenWrt:~# tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes


root@OpenWrt:~# kill -SIGUSR1 $(pidof udhcpc)
root@OpenWrt:~# 09:01:32.282872 IP (tos 0x0, ttl 64, id 418, offset 0, flags [DF], proto UDP (17), length 328)
    192.168.6.221.68 > 192.168.6.2.67: [udp sum ok] BOOTP/DHCP, Request from 18:a6:f7:7a:0d:7c, length 300, xid 0xa9174ad, Flags [none] (0x0000)
	  Client-IP 192.168.6.221
	  Client-Ethernet-Address 18:a6:f7:7a:0d:7c
	  Vendor-rfc1048 Extensions
	    Magic Cookie 0x63825363
	    DHCP-Message Option 53, length 1: Request
	    MSZ Option 57, length 2: 576
	    Parameter-Request Option 55, length 8: 
	      Subnet-Mask, Default-Gateway, Domain-Name-Server, Hostname
	      Domain-Name, BR, NTP, Classless-Static-Route
	    Vendor-Class Option 60, length 12: "udhcp 1.29.3"
	    Hostname Option 12, length 7: "OpenWrt"
	    END Option 255, length 0
	    PAD Option 0, length 0, occurs 19
09:01:32.283553 IP (tos 0x0, ttl 64, id 0, offset 0, flags [none], proto UDP (17), length 328)
    192.168.6.221.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 18:a6:f7:7a:0d:7c, length 300, xid 0xa9174ad, Flags [none] (0x0000)
	  Client-IP 192.168.6.221
	  Client-Ethernet-Address 18:a6:f7:7a:0d:7c
	  Vendor-rfc1048 Extensions
	    Magic Cookie 0x63825363
	    DHCP-Message Option 53, length 1: Request
	    MSZ Option 57, length 2: 576
	    Parameter-Request Option 55, length 8: 
	      Subnet-Mask, Default-Gateway, Domain-Name-Server, Hostname
	      Domain-Name, BR, NTP, Classless-Static-Route
	    Vendor-Class Option 60, length 12: "udhcp 1.29.3"
	    Hostname Option 12, length 7: "OpenWrt"
	    END Option 255, length 0
	    PAD Option 0, length 0, occurs 19
09:01:32.295570 IP (tos 0x0, ttl 60, id 28554, offset 0, flags [none], proto UDP (17), length 328)
    192.168.6.2.67 > 255.255.255.255.68: [udp sum ok] BOOTP/DHCP, Reply, length 300, xid 0xa9174ad, Flags [none] (0x0000)
	  Your-IP 192.168.6.221
	  Client-Ethernet-Address 18:a6:f7:7a:0d:7c
	  Vendor-rfc1048 Extensions
	    Magic Cookie 0x63825363
	    DHCP-Message Option 53, length 1: ACK
	    Server-ID Option 54, length 4: 192.168.6.2
	    Subnet-Mask Option 1, length 4: 255.255.255.0
	    Default-Gateway Option 3, length 4: 192.168.6.2
	    Domain-Name-Server Option 6, length 4: 192.168.6.2
	    Domain-Name Option 15, length 6: "intern"
	    BR Option 28, length 4: 192.168.6.255
	    Lease-Time Option 51, length 4: 30000
	    END Option 255, length 0
	    PAD Option 0, length 0, occurs 12
09:01:32.312032 IP (tos 0x0, ttl 60, id 28558, offset 0, flags [none], proto UDP (17), length 328)
    192.168.6.2.67 > 255.255.255.255.68: [udp sum ok] BOOTP/DHCP, Reply, length 300, xid 0xa9174ad, Flags [none] (0x0000)
	  Your-IP 192.168.6.221
	  Client-Ethernet-Address 18:a6:f7:7a:0d:7c
	  Vendor-rfc1048 Extensions
	    Magic Cookie 0x63825363
	    DHCP-Message Option 53, length 1: ACK
	    Server-ID Option 54, length 4: 192.168.6.2
	    Subnet-Mask Option 1, length 4: 255.255.255.0
	    Default-Gateway Option 3, length 4: 192.168.6.2
	    Domain-Name-Server Option 6, length 4: 192.168.6.2
	    Domain-Name Option 15, length 6: "intern"
	    BR Option 28, length 4: 192.168.6.255
	    Lease-Time Option 51, length 4: 30000
	    END Option 255, length 0
	    PAD Option 0, length 0, occurs 12



cat /tmp/resolv.conf.auto
nslookup google.com 192.168.6.2
root@OpenWrt:~# cat /tmp/resolv.conf.auto 
# Interface wan
nameserver 192.168.6.2
search intern


root@OpenWrt:~# nslookup google.com 192.168.6.2
Server:		192.168.6.2
Address:	192.168.6.2#53

Name:      google.com
Address 1: 216.58.210.14
Address 2: 2a00:1450:4001:81b::200e

I don't understand. When /tmp/resolv.conf.auto contains the nameserver why it isn't using it?

netstat -lnp | grep dnsmasq
nslookup example.org 192.168.6.2
nslookup example.org 127.0.0.1
nslookup example.org ::1
nslookup example.org $(uci get network.lan.ipaddr)
nslookup example.org $(uci get network.lan.ip6addr)
root@OpenWrt:~# netstat -lnp | grep dnsmasq
tcp        0      0 192.168.6.221:53        0.0.0.0:*               LISTEN      1171/dnsmasq
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      1171/dnsmasq
tcp        0      0 10.0.0.1:53             0.0.0.0:*               LISTEN      1171/dnsmasq
tcp        0      0 fe80::1aa6:f7ff:fe7a:d7c:53 :::*                    LISTEN      1171/dnsmasq
tcp        0      0 ::1:53                  :::*                    LISTEN      1171/dnsmasq
tcp        0      0 fd01:6665::2e0:99ff:feff:1001:53 :::*                    LISTEN      1171/dnsmasq
tcp        0      0 fe80::1aa6:f7ff:fe7a:d7b:53 :::*                    LISTEN      1171/dnsmasq
udp        0      0 192.168.6.221:53        0.0.0.0:*                           1171/dnsmasq
udp        0      0 127.0.0.1:53            0.0.0.0:*                           1171/dnsmasq
udp        0      0 10.0.0.1:53             0.0.0.0:*                           1171/dnsmasq
udp        0      0 0.0.0.0:67              0.0.0.0:*                           1171/dnsmasq
udp        0      0 fe80::1aa6:f7ff:fe7a:d7c:53 :::*                                1171/dnsmasq
udp        0      0 ::1:53                  :::*                                1171/dnsmasq
udp        0      0 fd01:6665::2e0:99ff:feff:1001:53 :::*                                1171/dnsmasq
udp        0      0 fe80::1aa6:f7ff:fe7a:d7b:53 :::*                                1171/dnsmasq

root@OpenWrt:~# nslookup openwrt.org 192.168.6.2
Server:		192.168.6.2
Address:	192.168.6.2#53

Name:      openwrt.org
Address 1: 139.59.209.225
Address 2: 2a03:b0c0:3:d0::1af1:1
root@OpenWrt:~# nslookup openwrt.org 127.0.0.1
Server:		127.0.0.1
Address:	127.0.0.1#53

Name:      openwrt.org
Address 1: 139.59.209.225
Address 2: 2a03:b0c0:3:d0::1af1:1

root@OpenWrt:~# nslookup openwrt.org $(uci get network.lan.ipaddr)
Server:		10.0.0.1
Address:	10.0.0.1#53

Name:      openwrt.org
Address 1: 139.59.209.225
Address 2: 2a03:b0c0:3:d0::1af1:1

Strange, it seems that nslookup on 127.0.0.1 allready knows.

ubus call system board

A similar issue: DNS Forwarding not working

root@OpenWrt:~# ubus call system board
{
	"kernel": "4.14.78",
	"hostname": "OpenWrt",
	"system": "Atheros AR9330 rev 1",
	"model": "TP-Link TL-WR710N v2.1",
	"board_name": "tl-wr710n",
	"release": {
		"distribution": "OpenWrt",
		"version": "SNAPSHOT",
		"revision": "r8389-f3b80c3",
		"target": "ar71xx\/generic",
		"description": "OpenWrt SNAPSHOT r8389-f3b80c3"
	}
}

I can't see a solution in your referred issue. Maybe my dnsmasq-configuration is wrong?

Actually some time ago there was another a topic about bugged dnsmasq in snapshot builds.
So try to use release version or at least some stable branch code.

Ok, i will give it a try. Thx

{
	"kernel": "4.9.135",
	"hostname": "OpenWrt",
	"system": "Atheros AR9330 rev 1",
	"model": "TP-Link TL-WR710N v2.1",
	"board_name": "tl-wr710n",
	"release": {
		"distribution": "OpenWrt",
		"version": "18.06-SNAPSHOT",
		"revision": "r7364-f1a2b5b",
		"target": "ar71xx\/generic",
		"description": "OpenWrt 18.06-SNAPSHOT r7364-f1a2b5b"
	}
}

Don't think it is the branch or the build. I checked out branch openwrt-18.06 and got still the same result. I think it is more about my configuration.

I remembered that i got problems with /etc/resolv.conf because it was a symlink to /tmp/resolv.conf and ruined my configuration. So i deleted the symlink and created by my own. I will test it, but this could be my problem.

Yes, with the symlink reestablished it worked with dhcp again. Now i have to find out how to add a nameserver when using static ip configuration despite my former problem.

Edit:
adding to option dns '192.168.6.2' to config interface 'wan' did the trick. Thx.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.