/etc/hosts problem

Issues related to configuring your network
Post Reply
redliquid
Posts: 4
Joined: 2015/08/05 13:12:58

/etc/hosts problem

Post by redliquid » 2022/06/29 11:03:25

os:CentOS Linux release 7.6.1810 (Core)
Linux CDH03 3.10.0-957

ip:
[root@CDH03 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:08:b8:c9 brd ff:ff:ff:ff:ff:ff
inet 192.168.80.13/24 brd 192.168.80.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe08:b8c9/64 scope link
valid_lft forever preferred_lft forever
3: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:08:b8:d3 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.237/24 brd 192.168.1.255 scope global dynamic ens34
valid_lft 6117sec preferred_lft 6117sec
inet6 fe80::20c:29ff:fe08:b8d3/64 scope link
valid_lft forever preferred_lft forever

/etc/hosts:
[root@CDH03 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.254 cdh01
192.168.1.235 cdh02
192.168.1.244 cdh04
192.168.1.237 cdh03
192.168.80.11 cdh01
192.168.80.12 cdh02
192.168.80.13 cdh03
192.168.80.14 cdh04
192.168.80.15 cdh05

problem:
[root@CDH03 ~]# ping cdh01 -c 1
PING cdh01 (192.168.80.11) 56(84) bytes of data.
^C
--- cdh01 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

if i disable 192.168.80.11 entry,can resolv 192.168.1.254

[root@CDH03 ~]# sed -i 's/192.168.80.11/#&/g' /etc/hosts
[root@CDH03 ~]# ping cdh01 -c 1
PING cdh01 (192.168.1.254) 56(84) bytes of data.
64 bytes from cdh01 (192.168.1.254): icmp_seq=1 ttl=64 time=4.63 ms

--- cdh01 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 4.632/4.632/4.632/0.000 ms

my os is mini install ,not install ncsd,bind rpm package

can anyone explain what's reason? why can't resolve first entry in /etc/hosts?
[root@CDH03 ~]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 ens34
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 ens33
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 ens34
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 ens34
192.168.80.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33

tunk
Posts: 1204
Joined: 2017/02/22 15:08:17

Re: /etc/hosts problem

Post by tunk » 2022/06/29 11:54:08

CentOS 7.6 has over three years accumulated security problems.
Run yum update to get 7.9.
Don't know what your problem is, but I seem to remember that it's
recommended to only have one GATEWAY setting in the ifcfg files.

User avatar
TrevorH
Site Admin
Posts: 33191
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: /etc/hosts problem

Post by TrevorH » 2022/06/29 12:02:51

You can only have one entry for any given name in /etc/hosts and the last one it finds is the one that gets used. You have numerous duplicates and none of the earlier ones will be used.

And 7.6? Really? yum update ASAP.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

redliquid
Posts: 4
Joined: 2015/08/05 13:12:58

Re: /etc/hosts problem

Post by redliquid » 2022/06/29 12:17:17

TrevorH wrote:
2022/06/29 12:02:51
You can only have one entry for any given name in /etc/hosts and the last one it finds is the one that gets used. You have numerous duplicates and none of the earlier ones will be used.

And 7.6? Really? yum update ASAP.
should be first match entry will be use,not last one.

redliquid
Posts: 4
Joined: 2015/08/05 13:12:58

Re: /etc/hosts problem

Post by redliquid » 2022/06/29 12:18:55

tunk wrote:
2022/06/29 11:54:08
CentOS 7.6 has over three years accumulated security problems.
Run yum update to get 7.9.
Don't know what your problem is, but I seem to remember that it's
recommended to only have one GATEWAY setting in the ifcfg files.
my question is first match entry not be used, can any way clear cache?

User avatar
TrevorH
Site Admin
Posts: 33191
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: /etc/hosts problem

Post by TrevorH » 2022/06/29 13:05:53

should be first match entry will be use,not last one.
I did some tests and they were inconclusive. On one system it used the first entry. On another it only ever used one of the entries whether it was first or second.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

Post Reply