Configure dnsmasq as stand-in for NAT hairpinning

0

I have a home server hosting a small website that I want to be able to access by name from within my LAN. Outside the LAN everything works fine, but my router does not support NAT hairpinning and, seemingly as a result, I cannot resolve my domain name from inside the LAN. I am trying to set up dnsmasq to resolve my domain to its local IP, and forward all other requests to, say 8.8.8.8.

My system is as follows:

  1. A wireless router at 192.168.2.1
  2. A webserver at 192.168.2.100
  3. dnsmasq running on the webserver box with the following settings: lines conf-dir=/etc/dnsmasq.d,.bak and conf-dir=/etc/dnsmasq.d,.bak uncommented in dnsmasq.conf and the additional settings

    domain-needed
    
    bogus-priv
    
    listen-address=127.0.0.1
    
    listen-address=192.168.2.1
    
    listen-address=192.168.1.1
    
    domain=mywebsite.com
    
    expand-hosts
    
    local=/mywebsite.com/
    
    no-dhcp-interface=enp2s0f0
    
    no-resolv
    
    no-poll
    
    server=8.8.8.8
    
    server=8.8.4.4
    

in a file in dnsmasq.d.

  1. /etc/hosts in my server looks like

    127.0.0.1 localhost

    192.168.2.100 MyServerName mydomain.tld

    The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters

  2. The router configured to use 192.168.2.100 as primary and secondary DNS.

  3. Port 53 ALLOW in ufw rules on webserver.

My webserver can ping itself using ping mydomain.tld and nslookup mydomain.tld shows it's resolving correctly to 192.168.2.100. But nslookup from any other machine on the network gives back the external IP of my website, and no other machine can ping my webserver at mydomain.tld from insider the LAN.

I feel my setup is close in principle but that either I'm missing something obvious, or something needs to be restarted or reloaded in order to get things working. I have tried flushing the dns cache of another machine on the LAN, and still nothing. Suggestions?

Stefan Dawydiak

Posted 2019-04-25T01:58:40.677

Reputation: 101

No answers