Skip to content

Instantly share code, notes, and snippets.

@ju1ius
Last active May 15, 2024 14:01
Show Gist options
  • Save ju1ius/944ad78f4db9188cd3cafc171aab8b98 to your computer and use it in GitHub Desktop.
Save ju1ius/944ad78f4db9188cd3cafc171aab8b98 to your computer and use it in GitHub Desktop.
Wildcard domains in /etc/hosts using NetworkManager

This gist is based off the fedoramagazine article about NetworkManager's dnsmasq plugin

1. Enable NetworkManager's dnsmasq plugin

$ cat /etc/NetworkManager/conf.d/00-use-dnsmasq.conf
# Enables the dnsmasq plugin.
[main]
dns=dnsmasq

2. Add some wildcards

$ cat /etc/NetworkManager/dnsmasq.d/00-dot-test.conf
# Resolve all *.test domains to localhost
address=/.test/127.0.0.1

3. Add domains from /etc/hosts

$ cat /etc/NetworkManager/dnsmasq.d/01-use-etc-hosts.conf
# By default, the dnsmasq plugin does not read from /etc/hosts.  
# This forces the plugin to slurp in the file.
#
# If you do not want to write to the /etc/hosts file, you can simply specify another one.
addn-hosts=/etc/hosts

4. Restart NetworkManager

systemctl restart NetworkManager.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment