Skip to content

dnsmasq

dnsmasq provides a DNS server, a DHCP server with support for DHCPv6 and PXE, and a TFTP server. It is designed to be lightweight and have a small footprint, suitable for resource constrained routers and firewalls. dnsmasq can also be configured to cache DNS queries for improved DNS lookup speeds to previously visited sites.

We will be only using the DNS server, to resolve *.qlico to your docker bridge network.

Linux

At the moment the Linux installation has been tested with >= Ubuntu 18.04.

First open the /etc/NetworkManager/NetworkManager.conf file with your favourite text editor, make sure you'll have sudo rights.

Under [main] add: dns=dnsmasq.

Now we need to tell our Operating System to use the resolv.conf created by NetworkManager, we'll move the old resolv.conf to resolv.conf.old and create a symlink to the one created by NetworkManager.

sudo mv /etc/resolv.conf /etc/resolv.conf.old
sudo ln -s /var/run/NetworkManager/resolv.conf /etc/resolv.conf

Now we'll need the IP address of your Docker bridge network, we will use this IP address in the next step.

ip addr show docker0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1

Now it's time to create a new dnsmasq configuration:

Use the IP address, you've received from the previous step (for example: 172.17.0.1), and place it in this line: address=/qlico/172.17.0.1

Open the file: /etc/NetworkManager/dnsmasq.d/qlico with your favourite text editor, make sure you'll have sudo rights. And add the following to the file, make sure you'll replace the IP address with the IP address from the previous step (if it's different).

domain-needed
bogus-priv
strict-order

address=/qlico/172.17.0.1

listen-address=::1,127.0.0.1

Finally, reload NetworkManager

sudo systemctl reload NetworkManager.service

macOS

To use dnsmasq on macOS we need to install it first, make sure you have homebrew installed.

After that open your favourite Terminal, and run the following commands.

brew install dnsmasq

Get the IP address of Docker for Mac.

docker run --rm -it alpine:latest nslookup host.docker.internal

Use the IP adress from:

Non-authoritative answer:
Name:   host.docker.internal
Address: 192.168.64.1
# Create a configuration folder
mkdir -pv $(brew --prefix)/etc/

# Create a dnsmasq configuration file
vim $(brew --prefix)/etc/dnsmasq.conf

Paste the following inside the file (remember to change the IP address when it's different):

address=/qlico/192.168.64.1
listen-address=127.0.0.1
port=35353

Finish with by running the following commands

# Always start dnsmasq when starting macOS.
sudo brew services start dnsmasq

# Create a dns resolver directory
sudo mkdir -v /etc/resolver

# Tell the resolver to use the local installed dnsmasq for the qlico tld. 
sudo bash -c 'echo "nameserver 127.0.0.1
port 35353" > /etc/resolver/qlico'

M1 chip

When using a MacBook with a M1 processor a workaround is required in order to be able to access docker containers from your local environment.

# Create a network alias to the localloopback ip
# (this is required after every reboot)
sudo ifconfig lo0 alias 10.254.254.254 255.255.255.0

# Edit the dnsmasq configuration file
sudo vim  $(brew --prefix)/etc/dnsmasq.conf

Replace the ip address you entered during the macOS setup above with the alias you created in the previous step.

address=/qlico/10.254.254.254

Restart dnsmasq

brew services stop dnsmasq
brew services start dnsmasq

Windows

Unfortunately dnsmasq is not available for Windows, if you have alternatives please contribute to the documentation.