После некоторого расследования и отчета об ошибке systemd я обнаружил вот что.
systemd -resolve получает всю информацию о DNS от systemd -networkd, поэтому сосредоточьтесь на systemd -networkd, так как исправление мошеннического сервера будет перетекать в systemd -resolve.
Данные хранятся в /var/run/systemd/netif/
с одним файлом на каждый интерфейс. Это внутреннее и может быть изменено, поэтому к тому времени, когда вы это прочтете, оно могло измениться, однако я смог найти эти файлы для мошеннического сервера и удалить файл, в котором он был. Когда я перезапустил systemd -networkd, он полностью воссоздал удаленный файл.
В моем случае он воссоздал файл с по-прежнему указанным мошенническим DNS-сервером, что означало, что он не кэшировался systemd, а скорее рекламировался где-то в сети.
Поскольку это был адрес IPv6, я установилradvd
(демон объявления маршрутизатора IPv6 )и запустил radvdump
, чтобы показать все RA IPv6, поступающие на машину. Конечно же, вскоре появился один с мошенническим DNS-сервером в списке, поэтому я мог найти его и исправить.
Если это не вариант для вас, есть некоторые сетевые опции systemd -, которые вы можете использовать для решения проблемы. Они должны быть помещены в один из файлов, в которых настроена ваша сеть(/etc/systemd/network/*.network
).
# Don't use DNS servers from DHCP responses received via IPv4 (default is true)
[DHCPv4]
UseDNS=false
# Don't use DNS servers from DHCPv6 responses received via IPv6 (default is true)
[DHCPv6]
UseDNS=false
[IPv6AcceptRA]
# Don't use DNS servers from IPv6 Router Advertisement (RA) messages (default is true)
UseDNS=false
# Don't start a DHCPv6 client when an RA message is received.
DHCPv6Client=false
Вы можете использовать эту команду:sudo systemd-resolve --flush-caches
илиsudo resolvectl flush-caches
(последнюю команду, взятую из справочной страницы из systemd-resolve
)
Чтобы проверить успешность сброса, используйте:sudo systemd-resolve --statistics
Пример вывода:
Cache
Current Cache Size: 0
Cache Hits: 101
Cache Misses: 256
Также обратите внимание на раздел systemd-resolve
справочной страницы о /etc/resolv.conf
, в каком режиме вы работаете?
/etc/resolv.conf
Four modes of handling /etc/resolv.conf (see resolv.conf(5)) are supported:
systemd-resolved maintains the /run/systemd/resolve/stub-resolv.conf file for compatibility with traditional Linux programs. This file may be symlinked from /etc/resolv.conf. This file lists the 127.0.0.53 DNS stub (see above) as the only DNS server. It also contains a list of search domains that are in use by systemd-resolved. The list of search domains is always kept up-to-date. Note that /run/systemd/resolve/stub-resolv.conf should not be used directly by applications, but only through a symlink from /etc/resolv.conf. This file may be symlinked from /etc/resolv.conf in order to connect all local clients that bypass local DNS APIs to systemd-resolved with correct search domains settings. This mode of operation is recommended.
A static file /usr/lib/systemd/resolv.conf is provided that lists the 127.0.0.53 DNS stub (see above) as only DNS server. This file may be symlinked from /etc/resolv.conf in order to connect all local clients that bypass local DNS APIs to systemd-resolved. This file does not contain any search domains.
systemd-resolved maintains the /run/systemd/resolve/resolv.conf file for compatibility with traditional Linux programs. This file may be symlinked from /etc/resolv.conf and is always kept up-to-date, containing information about all known DNS servers. Note the file format's limitations: it does not know a concept of per-interface DNS servers and hence only contains system-wide DNS server definitions. Note that /run/systemd/resolve/resolv.conf should not be used directly by applications, but only through a symlink from /etc/resolv.conf. If this mode of operation is used local clients that bypass any local DNS API will also bypass systemd-resolved and will talk directly to the known DNS servers.
Alternatively, /etc/resolv.conf may be managed by other packages, in which case systemd-resolved will read it for DNS configuration data. In this mode of operation systemd-resolved is consumer rather than provider of this configuration file.
Note that the selected mode of operation for this file is detected fully automatically, depending on whether /etc/resolv.conf is a symlink to /run/systemd/resolve/resolv.conf or lists 127.0.0.53 as DNS server.
/etc/resolv.conf
нельзя редактировать напрямую. И даже если вы это сделаете, изменения не вступят в силу даже при перезапуске соответствующей службы. Следующие шаги помогают мне удалить нежелательные настройки DNS из /etc/resolv.conf
на Ubuntu 20.04 desktop
.
sudo nano /etc/resolvconf/resolv.conf.d/head
systemctl stop resolvconf.service;systemctl start resolvconf.service