systemd-resolved はドメイン名をブロックします。

systemd-resolved はドメイン名をブロックします。

systemd-resolvedドメイン名をブラックホールまたはアドレスなしでブロック、ルーティング、または確認する方法を使用します。サブドメインにもボーナスポイントがあります。

単一ドメインを試してみました/etc/hosts

127.0.0.1 google.com
::1 google.com

私も次のことを試しました/etc/systemd/network/100-blocked.network

[Match]
Name=wlp113s0

[Network]
Description="Just block the domain, and sub domains"
DNS=127.0.0.255
DNS=::1

[Resolve]
Domains=google.com

sudo systemd-resolve --status:

Link 3 (wlp113s0)
      Current Scopes: DNS
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no
         DNS Servers: 127.0.0.255
                      ::1
                      2001:4888:3a:ff00:304:d::
                      2001:4888:39:ff00:308:d::

たとえば、次のようにしますdnsmasq

server=192.168.43.1
address=/google.com/0.0.0.0
# a very long list of "address=/domain/0"

関連:

ベストアンサー1

項目を追加する/etc/hostsと動作し、テストでは期待どおりに機能しました。私のテストはsystemd-239-9.git9f3aed1.fc30.x86_64バージョンのFedora Rawhideで行われたので、これはsystemdの最新のスナップショットであり、以前のバージョンは期待どおりに機能しないかもしれません。


アイテムを追加する前に/etc/hosts

1)クエリの解析:

$ resolvectl query google.com
google.com: 172.217.6.78

-- Information acquired via protocol DNS in 1.4ms.
-- Data is authenticated: no

2) フラット:

$ ping -c1 google.com
PING google.com (172.217.6.78) 56(84) bytes of data.
64 bytes from sfo07s17-in-f78.1e100.net (172.217.6.78): icmp_seq=1 ttl=54 time=12.4 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 12.435/12.435/12.435/0.000 ms

3)カール:

$ curl http://google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

項目を追加した後、この場合は/etc/hosts次のようになります。

$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

127.0.0.1 google.com
::1 google.com

テストの結果、ブロック操作が表示されました。

1)クエリの解析:

$ resolvectl query google.com
google.com: 127.0.0.1
            ::1

-- Information acquired via protocol DNS in 1.8ms.
-- Data is authenticated: yes

2) フラット:

$ ping -c1 google.com
PING google.com(localhost (::1)) 56 data bytes
64 bytes from localhost (::1): icmp_seq=1 ttl=64 time=0.613 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.613/0.613/0.613/0.000 ms

3)カール:

$ curl http://google.com
curl: (7) Failed to connect to google.com port 80: Connection refused

だからこのブロックがうまくいくようです。


最近、systemdに関する質問でこれが要求されたので、これがうまくいくと予想しました。問題 #9718ここでは何百万ものエントリを追加することが議論されており、/etc/hostsここに示すようにドメインをブラックリストに追加するユースケースがあります。

これには多くの可動部分があるため、この問題を解決するときに考慮することが重要です。

鉱山には/etc/systemd/resolved.confオーバーライド構成がなく、すべてのエントリがコメントアウトされており、ネットワーク設定はDHCPでsystemd-networkdを使用し、オーバーライドもありません。

出力には以下がresolvectl status含まれます。

Global
       LLMNR setting: yes
MulticastDNS setting: yes
  DNSOverTLS setting: no
      DNSSEC setting: allow-downgrade
    DNSSEC supported: no
Fallback DNS Servers: 8.8.8.8
                      8.8.4.4
                      2001:4860:4860::8888
                      2001:4860:4860::8844

Link 2 (ens33)
      Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
       LLMNR setting: yes
MulticastDNS setting: no
  DNSOverTLS setting: no
      DNSSEC setting: allow-downgrade
    DNSSEC supported: no

/etc/resolv.confスタブレゾルバを使用した構成:

$ ls -l /etc/resolv.conf
lrwxrwxrwx. 1 root root 39 Nov  7 22:08 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
$ grep '^[^#]' /etc/resolv.conf
nameserver 127.0.0.53

nsswitch.conf は、以下を使用するように構成されています。nssの解析(8)マニュアルページで提案されているように:

$ grep ^hosts: /etc/nsswitch.conf
hosts:      files resolve [!UNAVAIL=return] dns myhostname

それでも機能しない場合は、システムでこれらの設定を確認し、すべてが正しく構成されていることを確認できます。または、少なくとも現在の構成をここに(Linuxディストリビューションおよびシステムバージョンと共に)公開して、機能しない理由を診断するのに役立ちます。

おすすめ記事