时间:2021-11-29来源:www.pcxitongcheng.com作者:电脑系统城
下面配置两台centos7 虚拟机,主机名分别配置为client和server,它们主机IP 地址分别为192.168.30.8和192.168.30.9。
| 1 | [root@client ~]# vi /etc/sysconfig/network |
添加如下内容,保存:
| 1 2 3 |
# Created by anacondaNETWORKING=yeshostname=client |
| 1 | <span style="background-color: initial; font-family: Arial, Verdana, sans-serif;">重启网络:</span> |
| 1 2 3 4 |
[root@client ~]# systemctl restart network[root@client ~]# hostnameclient[root@client ~]# |
如果不生效可以使用如下命令:
| 1 | [root@client ~]# hostnamectl set-hostname client |
| 1 | [root@server ~]# hostnamectl set-hostname server |
重启网络:
| 1 2 3 4 5 |
[root@server ~]# systemctl restart network[root@server ~]# hostnameserver[root@server ~]# uname -nserver |
配置client和server的hosts文件
| 1 | vi /etc/hosts |
添加如下内容:
| 1 2 |
192.168.30.8 client192.168.30.9 server |
通过ping hostname来测试是否配置成功:
client ping server:
| 1 2 3 4 5 6 7 8 9 10 |
[root@client ~]# ping server -c 3PING 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 ms64 bytes from server (192.168.30.9): icmp_seq=2 ttl=64 time=0.384 ms64 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 2001msrtt min/avg/max/mdev = 0.384/0.522/0.616/0.099 ms[root@client ~]# <br> |
server ping client:
| 1 2 3 4 5 6 7 8 9 10 |
[root@Server ~]# ping client -c 3PING 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 ms64 bytes from client (192.168.30.8): icmp_seq=2 ttl=64 time=0.678 ms64 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 2003msrtt min/avg/max/mdev = 0.323/0.501/0.678/0.144 ms[root@Server ~]# <br> |
配置hostname与IP映射后,可以直接ping主机名而不用ping IP地址了。
配置windows hosts,以便在windows下面能通过主机名进行访问。
编辑 C:\Windows\System32\drivers\etc\hosts文件,添加如下内容:
| 1 2 |
192.168.30.8 client192.168.30.9 server |
保存
| 1 2 3 4 5 6 7 8 9 10 11 |
C:\Users\10287>ping client -n 3正在 Ping client [192.168.30.8] 具有 32 字节的数据:来自 192.168.30.8 的回复: 字节=32 时间<1ms TTL=64来自 192.168.30.8 的回复: 字节=32 时间<1ms TTL=64来自 192.168.30.8 的回复: 字节=32 时间<1ms TTL=64192.168.30.8 的 Ping 统计信息: 数据包: 已发送 = 3,已接收 = 3,丢失 = 0 (0% 丢失),往返行程的估计时间(以毫秒为单位): 最短 = 0ms,最长 = 0ms,平均 = 0ms |
到此这篇关于linux配置主机名详细介绍的文章就介绍到这了
2024-07-07
myeclipse怎么导入tomcat教程2024-07-07
myeclipse如何启动tomcat2024-07-07
myeclipse如何绑定tomcat上线了一个小的预约程序,配置通过Nginx进行访问入口,默认的日志是没有请求时间的,因此需要配置一下,将每一次的请求的访问响应时间记录出来,备查与优化使用....
2023-03-17