Fedora Core 500の技
Valid XHTML 1.0!
正当なCSSです!

TOP > Linux > Fedoraの技 > 001-100 > 014

hostsファイルを利用する

DNSにホストを追加する場合にはDNSサーバへ登録しますがローカル環境や単独のマシンだけ使えればいいときなどには/etc/hostsファイルの利用が便利です。このファイルにIPアドレスと対応するホスト名やFQDNを書くと自動的に認識されるようになります。

登録する前の状態。

# ping hello
ping: unknown host hello

helloというホストを登録します。

# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 server1.fedora500.jp server1 localhost.localdomain localhost
192.168.0.11 hello.fedora500.jp hello

今度は認識します。

# ping hello
PING hello.fedora500.jp (192.168.0.11) 56(84) bytes of data.
64 bytes from hello.fedora500.jp (192.168.0.11): icmp_seq=0 ttl=64 time=0.045 ms

/etc/hostsファイルを利用する、しないは/etc/nsswitch.confで指定しています。hosts指定の行でfilesを削除するとhostsファイルは利用されなくなります。

# vi /etc/nsswitch.conf
#hosts: db files nisplus nis dns
hosts: files dns このfilesを削除します

するとhelloは認識されなくなります。

# ping hello
ping: unknown host hello

2005-12-03 作成