如何添加dnsmasq并保持systemd-resolved(18.04)

我想用dnsmasq获得快速的DNS分辨率并保持默认的systemd-resolved。

寻找一种优雅的方式来做到这一点

我希望使用dnsmasq获得快速DNS解析,并保持默认的systemd-resolved / NetworkManager设置不受影响以备将来使用。 是的,dnsmasq的巨大dns缓存可以提高浏览速度。 是的,目标是保持默认的特色dns设置为18.04

  1. 安装dnmasq
  2. 配置它(监听地址和DNS服务器)
  3. 为手动DNS服务器地址配置NetWorkManager
  4. 检查validation

1 – 有了sudo

apt-get -y install dnsmasq 

2 – 有了sudo

 tee -a /etc/dnsmasq.conf << ENDdm interface=lo bind-interfaces listen-address=127.0.0.1 # DNS server from OpenDns. Use yours... server=208.67.222.222 server=208.67.220.220 ENDdm systemctl restart dnsmasq systemctl enable dnsmasq 

3 - 使用USER,配置NetworkManager

 # Get NM first active profile name NetManProfile=$(nmcli -t connection show --active | cut -f 01 -d ':') # remove, if exists, current dns servers nmcli con mod "$NetManProfile" ipv4.dns "" # set 'manual' dns server nmcli con mod "$NetManProfile" ipv4.ignore-auto-dns yes # set dnsmasq as manually set dns server nmcli con mod "$NetManProfile" ipv4.dns 127.0.0.1 # i also disabled ip6, do what u want nmcli con mod "$NetManProfile" ipv6.method ignore # reconnect to take effect nmcli connection down "$NetManProfile" nmcli connection up "$NetManProfile" 

4 - 检查validation

  • systemd-resolved在默认情况下应该在127.0.0.53上监听
  • dnsmasq在/ etc / dnsmasq中设置127.0.0.1
  • systemd-resolved从NetworkManager获取127.0.0.1
 netstat -antup Proto Recv-Q Send-Q Adresse locale Adresse distante Etat PID/Program name tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 1036/dnsmasq tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 766/systemd-resolve cat /run/systemd/resolve/resolv.conf nameserver 127.0.0.1 

Ubuntu 18.10

恕我直言,如果你要运行dnsmasq,你应该静态分配你的IP地址而不是从dhcp获取它。 这样您就可以一起禁用systemd-resolved。

  1. sudo apt-get install dnsmasq

  2. sudo systemctl禁用systemd-resolved

  3. sudo systemctl stop systemd-resolved

  4. 手动分配您的IP地址,网关,并将IP地址作为DNS分配给您的计算机。

  5. 配置/etc/dnsmasq.conf(真的…… RTFM – > man dnsmasq.conf)

  6. sudo systemctl启用dnsmasq

  7. 重启
  8. sudo systemctl status dnsmasq

  9. 将dhcp服务器上的dhcp指向shiny的新dnsmasq服务器(.. if yumpto)