红联Linux门户
Linux帮助

linux中ssh或是ping IP可以通但是主机名不通

发布时间:2016-03-02 15:44:47来源:linux网站作者:it_future

你需要修改一下/etc/hosts

在里面添加

主机ip 主机名

象这样

127.0.0.1               localhost.localdomain localhost

192.168.163.33      itcast06

一台机器配置另一台机器的主机名与ip映射,就可以用主机名互相访问了。你能够用localhost访问本机也是因为这个文件中有配置。

linux中ssh或是ping IP可以通但是主机名不通

然后就OK了,有了问题,再看下面这个:
ssh 192.168.229.131可以,ssh 主机名node2不行的问题

root@node1:~# ssh node2
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The ECDSA host key for node2 has changed,
and the key for the corresponding IP address 192.168.229.131
is unchanged. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
Offending key for IP in /root/.ssh/known_hosts:1
remove with: ssh-keygen -f "/root/.ssh/known_hosts" -R 192.168.229.131
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
4b:91:42:20:2a:5a:a6:9b:bb:db:98:bb:9d:ea:69:e5.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:5
remove with: ssh-keygen -f "/root/.ssh/known_hosts" -R node2
ECDSA host key for node2 has changed and you have requested strict checking.
Host key verification failed.
root@node1:~# ssh-keygen -f "/root/.ssh/known_hosts" -R node2
# Host node2 found: line 5 type ECDSA
/root/.ssh/known_hosts updated.
Original contents retained as /root/.ssh/known_hosts.old
root@node1:~# ssh node2
The authenticity of host 'node2 (192.168.229.131)' can't be established.
ECDSA key fingerprint is 4b:91:42:20:2a:5a:a6:9b:bb:db:98:bb:9d:ea:69:e5.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node2' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic i686)

* Documentation:  https://help.ubuntu.com/

Last login: Sun Feb 28 05:30:39 2016 from node3
root@node2:~#
下面是node3的截图,从node1中/root/.ssh/know_hosts中删除node3的密钥,然后就可以了。
【ssh-keygen -R hostname [-f known_hosts_file]
 -R hostname
从 known_hosts 文件中删除所有属于 hostname 的密钥。
这个选项主要用于删除经过散列的主机(参见 -H 选项)的密钥。】

linux中ssh或是ping IP可以通但是主机名不通


本文永久更新地址:http://www.linuxdiyf.com/linux/18560.html