Различные сопоставления IP:hostName для одного и того же хоста в `/etc/hosts`. Почему это работает?

awk 'BEGIN { print "     col1        |     col2     | col3" }
    /^\[730480.910233\] / {SA = $12 $13 $14 $15 $16 $17}
    /^\[730480.910247\] / { print SA $2 $3 " | " $4 $5 $6 $7 $8 $9 " | " $10 $11}
'  input.txt > new.txt
0
23.01.2020, 00:59
1 ответ

Я провел несколько тестов на своем debian/wsl

~$ uname -a
Linux DESKTOP-OMM8LBC 4.4.0-17763-Microsoft #864-Microsoft Thu Nov 07 15:22:00 PST 2019 x86_64 GNU/Linux

# /etc/hosts
172.22.5.107   www.wordpress-rend-adri.com # Unreachable IP from my LAN
216.58.198.164 www.wordpress-rend-adri.com # IP for www.google.com
192.168.0.12   www.wordpress-rend-adri.com # IP for another running machine on my LAN
157.240.1.35   www.wordpress-rend-adri.com # IP for www.facebook.com

~$ ping www.wordpress-rend-adri.com
PING www.wordpress-rend-adri.com (192.168.0.12) 56(84) bytes of data.
64 bytes from www.wordpress-rend-adri.com (192.168.0.12): icmp_seq=1 ttl=64 time=49.9 ms
64 bytes from www.wordpress-rend-adri.com (192.168.0.12): icmp_seq=2 ttl=64 time=5.85 ms
64 bytes from www.wordpress-rend-adri.com (192.168.0.12): icmp_seq=3 ttl=64 time=5.58 ms
64 bytes from www.wordpress-rend-adri.com (192.168.0.12): icmp_seq=4 ttl=64 time=6.25 ms
64 bytes from www.wordpress-rend-adri.com (192.168.0.12): icmp_seq=5 ttl=64 time=6.19 ms
--- www.wordpress-rend-adri.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 9ms
rtt min/avg/max/mdev = 5.575/14.754/49.919/17.584 ms

Итак, pingвыбрал локальный IP-адрес, расположенный между двумя рабочими IP-адресами WAN.

Второй тест:

/etc/hosts
172.22.5.107   www.wordpress-rend-adri.com # Unreachable IP from my LAN
216.58.198.164 www.wordpress-rend-adri.com # IP for www.google.com
#192.168.0.12   www.wordpress-rend-adri.com # IP for one running machine on my LAN
157.240.1.35   www.wordpress-rend-adri.com # IP for www.facebook.com

~$ ping www.wordpress-rend-adri.com
PING www.wordpress-rend-adri.com (172.22.5.107) 56(84) bytes of data.
# Stuck here

Третье испытание:

/etc/hosts
#172.22.5.107   www.wordpress-rend-adri.com # Unreachable IP from my LAN
216.58.198.164 www.wordpress-rend-adri.com # IP for www.google.com
#192.168.0.12   www.wordpress-rend-adri.com # IP for one running machine on my LAN
157.240.1.35   www.wordpress-rend-adri.com # IP for www.facebook.com

~$ ping www.wordpress-rend-adri.com
PING www.wordpress-rend-adri.com (216.58.198.164) 56(84) bytes of data.
64 bytes from www.wordpress-rend-adri.com (216.58.198.164): icmp_seq=1 ttl=54 time=24.5 ms
64 bytes from www.wordpress-rend-adri.com (216.58.198.164): icmp_seq=2 ttl=54 time=22.4 ms
64 bytes from www.wordpress-rend-adri.com (216.58.198.164): icmp_seq=3 ttl=54 time=21.7 ms
64 bytes from www.wordpress-rend-adri.com (216.58.198.164): icmp_seq=4 ttl=54 time=30.5 ms

--- www.wordpress-rend-adri.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 7ms
rtt min/avg/max/mdev = 21.734/24.768/30.457/3.440 ms

Четвертый тест:

/etc/hosts
#172.22.5.107  www.wordpress-rend-adri.com # Unreachable IP from my LAN
216.58.198.164 www.wordpress-rend-adri.com # IP for www.google.com
192.168.0.12   www.wordpress-rend-adri.com # IP for one running machine on my LAN
192.168.0.1    www.wordpress-rend-adri.com # IP for my router
157.240.1.35   www.wordpress-rend-adri.com # IP for www.facebook.com

~$ ping www.wordpress-rend-adri.com
PING www.wordpress-rend-adri.com (192.168.0.1) 56(84) bytes of data.
64 bytes from www.wordpress-rend-adri.com (192.168.0.1): icmp_seq=1 ttl=64 time=1.56 ms
64 bytes from www.wordpress-rend-adri.com (192.168.0.1): icmp_seq=2 ttl=64 time=1.35 ms

--- www.wordpress-rend-adri.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 2ms
rtt min/avg/max/mdev = 1.349/1.455/1.561/0.106 ms

Таким образом, мой вывод состоит в том, что pingне пробует один IP-адрес за другим. Он предпочитает маршрутизатор, локальный IP-адрес, а не IP-адрес WAN.

Обновление:

Выбранный выше IP-адрес подтверждается следующей командой python:

python -c 'import socket;print(socket.gethostbyname("www.wordpress-rend-adri.com"))'
1
28.01.2020, 02:54

Теги

Похожие вопросы