ITPub博客

首页 > Linux操作系统 > Linux操作系统 > linux 配置hostname

linux 配置hostname

原创 Linux操作系统 作者:yy418408247 时间:2022-09-06 15:48:01 0 删除 编辑

题外话:hostname是为了更好的识别服务器是做什么的,可以进行域名的设定。------文章起源我需要配置域名。


hostname配置 =主机名配置

查看hostname

方法一、临时配置hostname
[root@localhost ~]# hostname muqx  
[root@localhost ~]# bash   -- 及时生效
进行验证:
[root@muqx ~]# hostname

muqx

备注:适用于比较着急的情况;服务器或者虚拟机不能重启的情况。


方法二、永久生效配置hostname
1. 修改hosts文件
源文件内容:

[root@muqx ~]# cat /etc/hosts

[root@muqx ~]# vi /etc/hosts  或者 [root@muqx ~]# vim /etc/hosts  
i 进入编辑模式,在最后一行添加:192.168.1.140 muqx
Esc 退出编辑模式  
:wq 保存退出
或者 [root@muqx ~]# echo 192.168.1.140 muqx  >> /etc/hosts

本机ip地址:192.168.1.140
主机名:muqx    -- 自己需要的主机名,可以是任意的
格式: ip地址    hostname(主机名)
2.使其生效
#重启系统
[root@muqx ~]#reboot
#进行验证
[root@muqx ~]# hostname
muqx
#重启网络
[root@muqx ~]# systemctl restart network
#进行验证
[root@muqx ~]# ping muqx
PING muqx (192.168.1.140) 56(84) bytes of data.
64 bytes from muqx (192.168.1.140): icmp_seq=1 ttl=64 time=0.038 ms
64 bytes from muqx (192.168.1.140): icmp_seq=2 ttl=64 time=0.043 ms
64 bytes from muqx (192.168.1.140): icmp_seq=3 ttl=64 time=0.042 ms
64 bytes from muqx (192.168.1.140): icmp_seq=4 ttl=64 time=0.070 ms
^C
--- muqx ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 0.038/0.048/0.070/0.013 ms


游戏是我的全部图景,我将演绎所有的游戏角色,我是每个活着角色的传奇。   --开心研


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29494175/viewspace-2913642/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
游戏是我的全部图景,我将演绎所有的游戏角色,我是每个活着角色的传奇。 --开心研

注册时间:2014-02-19

  • 博文量
    44
  • 访问量
    63771