上QQ阅读APP看书,第一时间看更新
SSH using hostnames instead of IPs
In our examples so far, we've been using IP addresses to connect to our remote host.
SSH is also capable of connecting to hostnames.
First, we have to create a quick hosts entry so that we can resolve our name to an IP address:
[vagrant@centos1 ~]$ echo "192.168.33.11 centos2" | sudo tee -a /etc/hosts
The preceding code is a quick way to make a remote host resolvable to a name. There's no guarantee that it will stick on some systems, especially those where a third party controls the hosts file. In a real-world scenario, it is highly likely you'll have some sort of DNS setup that will make connecting to hostnames easier.
We should now be able to SSH using the host's name:
[vagrant@centos1 ~]$ ssh centos2
The authenticity of host 'centos2 (192.168.33.11)' can't be established.
ECDSA key fingerprint is SHA256:LKhW+WOnW2nxKO/PY5UO/ny3GP6hIs3m/ui6uy+Sj2E.
ECDSA key fingerprint is MD5:d5:77:4f:38:88:13:e7:f0:27:01:e2:dc:17:66:ed:46.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'centos2' (ECDSA) to the list of known hosts.
Enter passphrase for key '/home/vagrant/.ssh/id_rsa':
Last login: Wed Aug 8 11:28:59 2018 from fe80::a00:27ff:fe2a:1652%eth1
[vagrant@centos2 ~]$
Note that we once again had to accept the fingerprint of the host we're connecting to.