DNS resolving for "gateway"

Issues related to configuring your network
Post Reply
Tridariel
Posts: 3
Joined: 2021/03/22 10:03:31

DNS resolving for "gateway"

Post by Tridariel » 2021/03/22 10:10:57

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

User avatar
jlehtone
Posts: 3419
Joined: 2007/12/11 08:17:33
Location: Finland

Re: DNS resolving for "gateway"

Post by jlehtone » 2021/03/22 12:38:05

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.

Tridariel
Posts: 3
Joined: 2021/03/22 10:03:31

Re: DNS resolving for "gateway"

Post by Tridariel » 2021/03/23 10:16:42

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

BShT
Posts: 404
Joined: 2019/10/09 12:31:40

Re: DNS resolving for "gateway"

Post by BShT » 2021/03/23 11:50:00

try to dig it

Tridariel
Posts: 3
Joined: 2021/03/22 10:03:31

Re: DNS resolving for "gateway"

Post by Tridariel » 2021/03/24 08:45:03

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

User avatar
jlehtone
Posts: 3419
Joined: 2007/12/11 08:17:33
Location: Finland

Re: DNS resolving for "gateway"

Post by jlehtone » 2021/03/24 19:06:16

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.
Last edited by jlehtone on 2021/04/06 19:31:58, edited 1 time in total.

Whoever
Posts: 1203
Joined: 2013/09/06 03:12:10

Re: DNS resolving for "gateway"

Post by Whoever » 2021/03/24 20:29:29

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

aks
Posts: 3056
Joined: 2014/09/20 11:22:14

Re: DNS resolving for "gateway"

Post by aks » 2021/04/06 17:30:50

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....

Post Reply

Return to “CentOS 7 - Networking Support”