DNS是系统最常用的名称解析方法, 但DNS不是系统解析主机名和IP地址的唯一方法。/etc/nsswitch.conf 文件中的hosts行控制查找主机名的方式。hosts: files dns myhostname
1 2 3 4 5
[root@serverb ~]# cat /etc/nsswitch.conf | grep host # hosts: files dns # hosts: files dns # from user file hosts: files dns myhostname [root@serverb ~]#
files:首先在本地 /etc/hosts 文件中查找,可以手动指定主机名与 IP 地址之间的映射关系。如果主机名在该文件中找到匹配项,系统将直接使用该 IP 地址,不进行 DNS 查询。
[root@serverb ~]# dig blog.liruilong.com A @8.8.8.8
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el8 <<>> blog.liruilong.com A @8.8.8.8 ;; global options: +cmd ;; connection timed out; no servers could be reached [root@serverb ~]# dig blog.liruilong.com A @114.114.114.114
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el8 <<>> blog.liruilong.com A @114.114.114.114 ;; global options: +cmd ;; connection timed out; no servers could be reached
[root@serverb ~]# ping -c3 114.114.114.114 PING 114.114.114.114 (114.114.114.114) 56(84) bytes of data. From 172.25.252.254 icmp_seq=1 Destination Net Unreachable From 172.25.252.254 icmp_seq=2 Destination Net Unreachable From 172.25.252.254 icmp_seq=3 Destination Net Unreachable
; <<>> DiG 9.18.12-0ubuntu0.22.04.2-Ubuntu <<>> +trace liruilongs.github.io ;; global options: +cmd . 7105 IN NS e.root-servers.net. . 7105 IN NS f.root-servers.net. . 7105 IN NS a.root-servers.net. . 7105 IN NS m.root-servers.net. . 7105 IN NS g.root-servers.net. . 7105 IN NS h.root-servers.net. . 7105 IN NS i.root-servers.net. . 7105 IN NS c.root-servers.net. . 7105 IN NS d.root-servers.net. . 7105 IN NS j.root-servers.net. . 7105 IN NS b.root-servers.net. . 7105 IN NS l.root-servers.net. . 7105 IN NS k.root-servers.net. ;; Received 239 bytes from 127.0.0.53#53(127.0.0.53) in 0 ms
io. 172800 IN NS c0.nic.io. io. 172800 IN NS a2.nic.io. io. 172800 IN NS a0.nic.io. io. 172800 IN NS b0.nic.io. io. 86400 IN DS 57355 8 2 95A57C3BAB7849DBCDDF7C72ADA71A88146B141110318CA5BE672057 E865C3E2 io. 86400 IN RRSIG DS 8 1 86400 20230812140000 20230730130000 11019 . PQxqrG5/DAsu9RBIZN4Ol4lzzGkMBzyDxsC0lI+l8HDz5qTocF2tx8+F CYOeqJ235GhJI6cqMs0qFSMd9yHKupIllXOvrIBTgcJ/a8hoyXxoWyQL iwFJ8lj3+Wc3VSdHGvkqWYMZ52Ny9orne3zqTOzpGV1xtyxAiw+a9h92 hufkRTmoki6jMdiIFlVhQIHzqtc4MY/HmuUhOjbn0/b3432XAeeJx+uw sRqaFgs6K//QdvllYATpgnXoZ2RdgJuIsmEF1HfDY2vg+O3y4DMW4htU EkQiBqHx6aVPCAaCK5nkp7UEzZfgfhkugxGl1ikxaXn0mBt8awkkCIaa H9l2rw== ;; Received 636 bytes from 202.12.27.33#53(m.root-servers.net) in 68 ms
;; UDP setup with 2a01:8840:9e::17#53(2a01:8840:9e::17) for liruilongs.github.io failed: network unreachable. ;; UDP setup with 2a01:8840:9e::17#53(2a01:8840:9e::17) for liruilongs.github.io failed: network unreachable. ;; UDP setup with 2a01:8840:9e::17#53(2a01:8840:9e::17) for liruilongs.github.io failed: network unreachable. ;; communications error to 65.22.160.17#53: timed out github.io. 3600 IN NS dns1.p05.nsone.net. github.io. 3600 IN NS dns2.p05.nsone.net. github.io. 3600 IN NS dns3.p05.nsone.net. github.io. 3600 IN NS ns-692.awsdns-22.net. github.io. 3600 IN NS ns-1622.awsdns-10.co.uk. 0d790076pp5pfktg2hrthj5bj6ckckcb.io. 3600 IN NSEC3 1 1 10 332539EE7F95C32A 0D7N522D3BFMA1LA01BUIOBUK6MROGMU NS SOA RRSIG DNSKEY NSEC3PARAM 0d790076pp5pfktg2hrthj5bj6ckckcb.io. 3600 IN RRSIG NSEC3 8 2 3600 20230820161400 20230730151400 47703 io. eJVfgk+RJy6pJULS8AGI5vdwg5l5aheH3AXAAEedhWaDV2RZ5wkjG55M NnnWLDfRYPSCJjQwlDeYLqxLbwcIZVKFYAI2bGcMp5gwF+3N8GKobO0J fufmVtT2feylQnFVC414+dRVmfswmycKiVqYz+R5evDJVvlba47Nw2jk +uw= 0jehpe7obc68rhh4ntet0u9o44qmosmo.io. 3600 IN NSEC3 1 1 10 332539EE7F95C32A 0JES1F5OD9SG1E4CCRGBS865PMBUV4PC NS DS RRSIG 0jehpe7obc68rhh4ntet0u9o44qmosmo.io. 3600 IN RRSIG NSEC3 8 2 3600 20230815155455 20230725145455 47703 io. YGikk+waO8SYkaBCCNiFjRwXRmjJWGhfk7g1iTAPUz3a8WHtZ/MJSjMc uQPhpbfl7h2Bq0//Gcl657brOnAGL4/pa8Bo0gyWhDLQDPGQe+DNPm+t LFNAd4V/oJw747ch2bAJW4U+zSkCmY/WVlCwuht82Z37mMrRRilt7HZ9 UnQ= ;; Received 686 bytes from 65.22.162.17#53(c0.nic.io) in 120 ms
;; UDP setup with 2600:9000:5306:5600::1#53(2600:9000:5306:5600::1) for liruilongs.github.io failed: network unreachable. ;; UDP setup with 2620:4d:4000:6259:7:5:0:1#53(2620:4d:4000:6259:7:5:0:1) for liruilongs.github.io failed: network unreachable. liruilongs.github.io. 3600 IN A 185.199.108.153 liruilongs.github.io. 3600 IN A 185.199.109.153 liruilongs.github.io. 3600 IN A 185.199.110.153 liruilongs.github.io. 3600 IN A 185.199.111.153 ;; Received 113 bytes from 198.51.44.69#53(dns3.p05.nsone.net) in 48 ms