Jump to content

How to use local domains (.test) on Linux with the help of dnsmasq (compatible with Docker)


Beluga
 Share

Recommended Posts

Some weeks ago I started developing a fairly simple multisite using Soma's module, so I was suddenly faced with the need to use "fake domains" locally. After a lot of digging I happened upon a setup that works perfectly with Docker. I was surprised about how smooth it was in the end, because I had read a crazy amount of topics dealing with weird acrobatic methods to achieve this with Docker.

I used a tutorial on setting up DNS caching (they have an Ubuntu version as well). It worked fine with my Arch Linux. Later I noticed Arch wiki has a topic about the same thing.

My /etc/dnsmasq.conf looks like this:

listen-address=127.0.0.1
port=53
bind-interfaces
user=dnsmasq
group=dnsmasq
pid-file=/var/run/dnsmasq.pid
domain-needed
bogus-priv
no-hosts
dns-forward-max=150
cache-size=1000
no-negcache
neg-ttl=3600
resolv-file=/etc/resolv.dnsmasq
no-poll
address=/test/127.0.0.1

The last line allows me to use any .test domain.

I copied the old contents of my /etc/resolv.conf to /etc/resolv.dnsmasq.

I changed /etc/resolv.conf to only contain

nameserver 127.0.0.1

Then just sudo systemctl restart dnsmasq to see the thing in action.

Finally, I had to protect /etc/resolv.conf. There are various ways, but I found I only needed to stop NetworkManager from overwriting it. In /etc/NetworkManager/NetworkManager.conf I added

[main]
dns=none

Now I just use this in my Caddyfile and enjoy life:

mysite.test, anothersite.test
tls off

  • Like 2
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...