Skip to content

Instantly share code, notes, and snippets.

@166MMX
Created September 22, 2022 05:56
Show Gist options
  • Save 166MMX/56be05fb4d3198de46b1a27ac79e77b5 to your computer and use it in GitHub Desktop.
Save 166MMX/56be05fb4d3198de46b1a27ac79e77b5 to your computer and use it in GitHub Desktop.
dnsmasq with NetworkManage and systemd-resolved Ubuntu 22.04
#!/usr/bin/env sh
# Install and use dnsmasq with NetworkManage support
# along side with systemd-resolved by disableing DNS stub listener
# on Ubuntu 22.04.1 LTS (Jammy Jellyfish)
# https://superuser.com/questions/681993/using-dnsmasq-with-networkmanager
# https://askubuntu.com/questions/1393486/dnsmasq-and-networkmanager-dns
# https://unix.stackexchange.com/questions/304050/how-to-avoid-conflicts-between-dnsmasq-and-systemd-resolved
# https://askubuntu.com/questions/1032450/how-to-add-dnsmasq-and-keep-systemd-resolved-18-04-to-20-04
# man -- NetworkManager.conf | sed '/^$/d' | sed -n '$p' | sed -E 's/ {3,39}/;/g' | cut '-d;' -f1
# systemd 249
# NetworkManager 1.36.6
sudo apt-get install dnsmasq
sudo mkdir -p /etc/systemd/resolved.conf.d
SUDO_EDITOR="cp /dev/stdin" sudoedit /etc/systemd/resolved.conf.d/disable-dns-stub-listener.conf <<EOF
[Resolve]
DNSStubListener=no
EOF
sudo mkdir -p /etc/NetworkManager/conf.d
SUDO_EDITOR="cp /dev/stdin" sudoedit /etc/NetworkManager/conf.d/use-dnsmasq-for-dns.conf <<EOF
[main]
dns=dnsmasq
EOF
sudo systemctl daemon-reload
sudo systemctl enable dnsmasq
sudo systemctl start dnsmasq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment