Page 1 of 1

DNS resolving for "gateway"

Posted: 2021/03/22 10:10:57
by Tridariel
Hello community,

can I kindly share with you this following issue please. We experience a problem with this feature.

if from terminal i type:

ping gateway

[root@xxx ~]# ping gateway
PING gateway (10.3.6.1) 56(84) bytes of data.
64 bytes from gateway (10.3.6.1): icmp_seq=1 ttl=255 time=0.746 ms
64 bytes from gateway (10.3.6.1): icmp_seq=2 ttl=255 time=0.828 ms
64 bytes from gateway (10.3.6.1): icmp_seq=3 ttl=255 time=0.803 ms

it returns the IP of my set gateway no matter if the "gateway" is in my DNS server or not. I am using CentOS Linux release 7.9.2009 (Core).

If I try the same on this following system it does not work: CentOS Stream release 8

[root@yyy ~]# ping gateway
ping: gateway: Name or service not known

So the desired behavior is not to have the word gateway translated to the set "default gateway".

Does anyone have any clue why it acts this way and if so, how to turn it off please?

Thanks in advance.
David

Re: DNS resolving for "gateway"

Posted: 2021/03/22 12:38:05
by jlehtone
When you type ping gateway your machine has to resolve the name "gateway" into an IP address.
Then ping will use that IP address.

How does one resolve? On my machine:

Code: Select all

$ grep ^hosts /etc/nsswitch.conf
hosts:      files dns myhostname
System first looks from "files" and then asks from DNS server.
The "files" is /etc/hosts. If it has entry for "gateway", then that is used.

If system has to ask from DNS server, then whom does it ask from?
It starts with the first "nameserver" that is in /etc/resolv.conf


None of that is directly related to the router(s) that the subnet(s) has.

Re: DNS resolving for "gateway"

Posted: 2021/03/23 10:16:42
by Tridariel
Hello,

thank you for your reply. I understand the process of the lookup. The thing I dont understand is why on CentOS 7 this following works:

Code: Select all

[root@xxx]# ping gateway
PING gateway (10.2.9.1) 56(84) bytes of data.
64 bytes from gateway (10.2.9.1): icmp_seq=1 ttl=255 time=0.797 ms
64 bytes from gateway (10.2.9.1): icmp_seq=2 ttl=255 time=0.875 ms
64 bytes from gateway (10.2.9.1): icmp_seq=3 ttl=255 time=0.884 ms
64 bytes from gateway (10.2.9.1): icmp_seq=4 ttl=255 time=0.803 ms
But there is no "gateway" in hosts file, nor is it in any configured DNS server.

So how does it translate the word "gateway" to the IP address of my set default gateway?

David

Re: DNS resolving for "gateway"

Posted: 2021/03/23 11:50:00
by BShT
try to dig it

Re: DNS resolving for "gateway"

Posted: 2021/03/24 08:45:03
by Tridariel
Hello,

this is output from dig command from Centos 7 where gateway resolves to ip address:

Code: Select all

[root@xxx]# dig gateway

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.4 <<>> gateway
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 11726
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;gateway.                       IN      A

;; Query time: 0 msec
;; SERVER: 10.2.2.10#53(10.2.2.10)
;; WHEN: Wed Mar 24 09:41:01 CET 2021
;; MSG SIZE  rcvd: 36
this is output from dig command from Centos 8 where gateway does not resolve to anything:

Code: Select all

[root@yyy]# dig gateway

; <<>> DiG 9.11.26-RedHat-9.11.26-3.el8 <<>> gateway
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 33423
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;gateway.                       IN      A

;; Query time: 0 msec
;; SERVER: 10.2.2.10#53(10.2.2.10)
;; WHEN: Wed Mar 24 09:40:14 CET 2021
;; MSG SIZE  rcvd: 36
Outputs are same, so I expect this being some "feature" of Centos 7, where it automatically resolves word "gateway" to set ip address of the default gateway.

David

Re: DNS resolving for "gateway"

Posted: 2021/03/24 19:06:16
by jlehtone
It is not a feature of CentOS 7. It must be within your custom configuration somehow.

[EDIT] :shock: My mistake, it is a feature, as told below. I did not use correct setup/test to find it.

Re: DNS resolving for "gateway"

Posted: 2021/03/24 20:29:29
by Whoever
It appears to be a feature of systemd-resolved.

Search for "gateway" on this page:
https://www.freedesktop.org/software/sy ... rvice.html

This page has a description of the same behavior, even when systemd-resolved is disabled:
https://askubuntu.com/questions/806778/ ... -change-it

Re: DNS resolving for "gateway"

Posted: 2021/04/06 17:30:50
by aks
Actually it's from the NSS myhostname module (https://www.freedesktop.org/software/sy ... tname.html) & (as noted in the above) it's actually _gateway, so not systemd-resolved....