OpenWRT – Redirect All Subdomains to Same Host for Reverse Proxy

domain-name-systemopenwrtreverse-proxyroutingsubdomain

I have an OpenWRT router setup, 192.168.1.1, with search domain, local (as opposed to the default lan).

I have a server setup, 192.168.1.200, with hostname, server.local.

I have a workstation, 192.168.1.10, with hostname, workstation.local.

server.local also operates an NGINX reverse proxy, to provide subdomains such as, sub.server.local.

If my workstation tries to access, server.local, it is resolved correctly to point at 192.168.1.200.

However, if my workstation tries to access, sub.server.local, it can't resolve to 192.168.1.200.

If my workstation has 192.168.1.200 sub.server.local, added to its hosts file, it resolves correctly, and the servers reverse proxy routes the incoming connection to the correct port.

How do I fix this, so that all subdomains of server.local resolve to 192.168.1.200? Without having to add a hosts record to every workstation, for every subdomain on the server, which is obviously not sustainable.

I'm assuming that I need to alter some DNS records on my OpenWRT router, but looking through the settings in Luci (the web interface), nothing sticks out as being capable of achieving this.

Any ideas?

Best Answer

I sorted it out eventually.

According to:

https://openwrt.org/docs/guide-user/base-system/dhcp_configuration#a_and_aaaa_rr

Which states:

This is an implementation of the --address option. Return 10.10.10.1 on query domain home and subdomain *.home.

I was able to login to OpenWRT (using ssh root@192.168.1.1), and running:

uci add_list dhcp.@dnsmasq[0].address="/server.local/192.168.1.200"
uci commit dhcp
/etc/init.d/dnsmasq restart

Which then allows the following to work:

~$ ping www.server.local

PING www.server.local (192.168.1.200) 56(84) bytes of data.
64 bytes from server.local (192.168.1.200): icmp_seq=1 ttl=63 time=55.4 ms
64 bytes from server.local (192.168.1.200): icmp_seq=2 ttl=63 time=77.3 ms

And anything else for that matter:

~$ ping hdsjdjk.server.local

PING hdsjdjk.server.local (192.168.1.200) 56(84) bytes of data.
64 bytes from server.local (192.168.1.200): icmp_seq=1 ttl=63 time=101 ms
64 bytes from server.local (192.168.1.200): icmp_seq=2 ttl=63 time=124 ms

As I understand it, this creates an A record in DNSMasq, which automatically includes all subdomains.

The changes can be seen in /etc/config/dhcp, which now looks (partially) like:

config dnsmasq
        [...]
        option domain 'local'
        option local '/local/'
        list address '/server.local/192.168.1.200'

[...]

Hopefully this helps someone else in the future!