1. 配置Linux hostname
下面配置两台centos7 虚拟机,主机名分别配置为client和server,它们主机IP 地址分别为192.168.30.8和192.168.30.9。
配置client主机
[root@client ~]# vi /etc/sysconfig/network添加如下内容,保存:
# Created by anaconda NETWORKING=yes hostname=client重启网络:[root@client ~]# systemctl restart network [root@client ~]# hostname client [root@client ~]#如果不生效可以使用如下命令:
[root@client ~]# hostnamectl set-hostname client配置server主机
[root@server ~]# hostnamectl set-hostname server重启网络:
[root@server ~]# systemctl restart network [root@server ~]# hostname server [root@server ~]# uname -n server2. 配置hostname与IP映射
配置client和server的hosts文件
vi /etc/hosts添加如下内容:
192.168.30.8 client 192.168.30.9 server3. 测试
通过ping hostname来测试是否配置成功:
client ping server:
[root@client ~]# ping server -c 3 PING server (192.168.30.9) 56(84) bytes of data. 64 bytes from server (192.168.30.9): icmp_seq=1 ttl=64 time=0.616 ms 64 bytes from server (192.168.30.9): icmp_seq=2 ttl=64 time=0.384 ms 64 bytes from server (192.168.30.9): icmp_seq=3 ttl=64 time=0.566 ms — server ping statistics — 3 packets transmitted, 3 received, 0% packet loss, time 2001ms rtt min/avg/max/mdev = 0.384/0.522/0.616/0.099 ms [root@client ~]#
server ping client:
[root@Server ~]# ping client -c 3 PING client (192.168.30.8) 56(84) bytes of data. 64 bytes from client (192.168.30.8): icmp_seq=1 ttl=64 time=0.502 ms 64 bytes from client (192.168.30.8): icmp_seq=2 ttl=64 time=0.678 ms 64 bytes from client (192.168.30.8): icmp_seq=3 ttl=64 time=0.323 ms — client ping statistics — 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 0.323/0.501/0.678/0.144 ms [root@Server ~]#
配置hostname与IP映射后,可以直接ping主机名而不用ping IP地址了。
4. 配置windows hosts
配置windows hosts,以便在windows下面能通过主机名进行访问。
编辑 C:WindowsSystem32driversetchosts文件,添加如下内容:
192.168.30.8 client 192.168.30.9 server保存
暂无评论内容