CentOS/RHEL中的“_gateway”变量是个什么东西?

What kind of a thing is the "_gateway" variable in CentOS/RHEL?

我已经知道 CentOS/RHEL 中的“_gateway”变量(我认为最多 7 个它只是“网关”,没有 _ 符号)。今天我在我的家庭实验室设置了 AdGuard DNS 服务器,在同一台机器上是一个反向代理来服务一些内部服务,我为主机添加了第二个 IP,因为我需要多个 HTTP 端口。没关系,我在 adguard 上设置了通配符 DNS 条目。像这样:*.mydomain.com172.16.20.60(也就是上面提到的反向代理的IP)——不想手动添加所有服务,所以选择了通配符的方式。

几个小时后,我注意到托管 dns 服务器和反向代理的机器无法连接到互联网。

我做了一个 traceroute,发现它正试图通过 _gateway 访问互联网。mydomain.com(这导致机器本身)。

_gateway 上的 ping。mydomain.com 返回了机器 IP,所以我记得我的 dns 服务器上的通配符 dns 条目。我将 _gateway.mydomain.com 添加到它的正确 IP,然后它按预期工作。

我的问题是这种环境变量“_gateway”/“gateway”是怎么回事 - 为什么 RedHat 这样做?我想知道为什么网络会尝试通过 dns 名称访问它的网关? 我找不到任何关于此的信息,也没有在机器本身上找到任何设置来禁用此行为。

这是一些输出:

ping _gateway
PING _gateway.mydomain.com (172.16.20.10) 56(84) bytes of data.
64 bytes from _gateway (172.16.20.10): icmp_seq=1 ttl=64 time=0.112 ms
64 bytes from _gateway (172.16.20.10): icmp_seq=2 ttl=64 time=0.285 ms
64 bytes from _gateway (172.16.20.10): icmp_seq=3 ttl=64 time=0.190 ms
64 bytes from _gateway (172.16.20.10): icmp_seq=4 ttl=64 time=0.284 ms
host _gateway
_gateway.mydomain.com has address 172.16.20.10

有什么想法吗?

谢谢

由于似乎没有人知道我的意思,所以我自己清除了这个。 我在 Ubuntu 上看到了同样的事情,这让我得出结论,它可能与 systemd 有关……是的,宾果游戏!

根据 https://www.freedesktop.org/software/systemd/man/systemd-resolved.service.html 说:

The hostname "_gateway" is resolved to all current default routing gateway addresses, ordered by their metric. This assigns a stable hostname to the current gateway, useful for referencing it independently of the current network configuration state.

我没有进一步调查以禁用此行为,无论如何我知道它来自哪里,谢谢 systemd ...