本网站(662p.com)打包出售,且带程序代码数据,662p.com域名,程序内核采用TP框架开发,需要联系扣扣:2360248666 /wx:lianweikj
精品域名一口价出售:1y1m.com(350元) ,6b7b.com(400元) , 5k5j.com(380元) , yayj.com(1800元), jiongzhun.com(1000元) , niuzen.com(2800元) , zennei.com(5000元)
需要联系扣扣:2360248666 /wx:lianweikj
linux配置主机名详细介绍
itnanba · 218浏览 · 发布于2021-11-30 +关注

大家好,本篇文章主要讲的是linux配置主机名详细介绍,感兴趣的同学赶快来看一看吧,对你有帮助的话记得收藏一下哦,方便下次浏览

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

<span style="background-color: initial; font-family: Arial, Verdana, sans-serif;">重启网络:</span>

[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
server


2. 配置hostname与IP映射

配置client和server的hosts文件

vi /etc/hosts

添加如下内容: 

192.168.30.8 client
192.168.30.9 server


3. 测试

通过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 ~]# <br data-filtered="filtered">

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 ~]# <br data-filtered="filtered">

配置hostname与IP映射后,可以直接ping主机名而不用ping IP地址了。 

4. 配置windows hosts

配置windows hosts,以便在windows下面能通过主机名进行访问。

编辑 C:\Windows\System32\drivers\etc\hosts文件,添加如下内容:

192.168.30.8 client
192.168.30.9 server

保存 

5. windows测试

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=64
192.168.30.8 的 Ping 统计信息:
    数据包: 已发送 = 3,已接收 = 3,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms


 


相关推荐

将Fedora 29升级到Fedora 30

吴振华 · 701浏览 · 2019-05-14 22:00:02
使用Nginx反向代理到go-fastdfs

iamitnan · 723浏览 · 2019-05-23 13:42:00
利用VLC搭建组播流服务器

追忆似水年华 · 2690浏览 · 2019-06-14 11:27:06
用Bash脚本监控Linux上的内存使用情况

吴振华 · 971浏览 · 2019-06-24 11:27:02
加载中

0评论

评论
分类专栏
小鸟云服务器
扫码进入手机网页