问题现象:
已经在hosts文件配置好了域名,发现配置的不生效
[root@reg ta]# head /etc/hosts
127.0.0.1 localhost
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@reg ta]# ping localhost
ping: localhost: Name or service not known
解决:
发现nsswitch.conf的配置文件hosts属性冒号是中文的,改回英文的就可以了
#旧的
[root@iZuf6hd51mz5z31be327a7Z ~]# cat /etc/nsswitch.conf|grep hosts
#hosts: db files nisplus nis dns
hosts: files dns myhostname
#新的
[root@iZuf6hd51mz5z31be327a7Z ~]# cat /etc/nsswitch.conf|grep hosts
#hosts: db files nisplus nis dns
hosts: files dns myhostname
效果:
[root@iZuf6hd51mz5z31be327a7Z ~]# ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.029 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.019 ms