修正する

修正する

私のサーバーのホスト名ファイルの内容は次のとおりです。

# cat /etc/hostname
sub.mysite.com

しかし、私のpingCentOS 7サーバーに次のものが表示された場合:

# ping sub.mysite.com
64 bytes from sub ...

でも:

# ping ns1.mysite.com
    64 bytes from sub ...

pingを実行するときにサーバーに次の出力が表示されるようにするにはどうすればよいですか?

64 bytes from sub.mysite.com ...

修正する

私の顧客を例に挙げましょう。

user@host:~$ ping ns1.mysite.com
PING ns1.mysite.com (x.x.x.x) 56(84) bytes of data.
64 bytes from sub (x.x.x.x): icmp_seq=1 ttl=56 time=7.88 ms
64 bytes from sub (x.x.x.x): icmp_seq=2 ttl=56 time=5.86 ms
64 bytes from sub (x.x.x.x): icmp_seq=3 ttl=56 time=4.99 ms
64 bytes from sub (x.x.x.x): icmp_seq=4 ttl=56 time=4.88 ms

。代わりに、完全なホスト名(sub.mysite.com)が必要ですsub

ベストアンサー1

ping/etc/hostnameIPを名前マッピングとして解決するのではなく、NameService(s netns)を使用してこれらの変換を実行します。ところで、/etc/hostnameそれはsystemdの一部です。

$ rpm -qf /etc/hostname
systemd-219-42.el7_4.10.x86_64

表示される短い名前は、subネームサービスを介してファイルからインポートされます。/etc/hosts以下を使用して、それを見つけるstrace方法を確認できます。pingsub

$ strace -s 2000 ping -c1 www.google.com |& grep /etc/host
open("/etc/host.conf", O_RDONLY|O_CLOEXEC) = 4
open("/etc/hosts", O_RDONLY|O_CLOEXEC)  = 4
open("/etc/hosts", O_RDONLY|O_CLOEXEC)  = 4

pingしたがって、問題を解決する簡単な方法は、表示したいサーバー名を/etc/hostsファイルに入れることです。

はい

$ ping -c1 www.google.com
PING www.google.com (74.125.141.99) 56(84) bytes of data.
64 bytes from vl-in-f99.1e100.net (74.125.141.99): icmp_seq=1 ttl=63 time=109 ms

--- www.google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 109.903/109.903/109.903/0.000 ms
Now if we were to add that IP, 74.125.141.103, to your `/etc/hosts` file we could manipulate `ping` into showing whatever we want for it:

次の項目に追加してください/etc/hosts

74.125.141.99  blah.blah.com

ここでテストを繰り返します。

$ ping -c1 www.google.com
PING www.google.com (74.125.141.99) 56(84) bytes of data.
64 bytes from blah.blah.com (74.125.141.99): icmp_seq=1 ttl=63 time=109 ms

--- www.google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 109.886/109.886/109.886/0.000 ms

/etc/hostsの順序

/etc/hostsホストを追加する順序によっては、名前が表示されるように表示されることがあります。

たとえば、次のような場合/etc/hosts:

74.125.141.99  blah blah.blah.com

ping見えるように短い名前で表示されます。

$ ping -c1 www.google.com
PING www.google.com (74.125.141.99) 56(84) bytes of data.
64 bytes from blah (74.125.141.99): icmp_seq=1 ttl=63 time=108 ms

--- www.google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 108.065/108.065/108.065/0.000 ms

引用する

おすすめ記事