1、临时修改主机名

hostname 主机名

重新连接shell,就可以,这种方式,只能修改临时的主机名,当重启机器后,主机名称又变回来了。

2、永久修改主机名

hostnamectl set-hostname <hostname>

reboot,重启系统

重新连接shell,使用这种方式修改,可以永久性的修改主机名称!

需要修改两处:一处是/etc/sysconfig/network,另一处是/etc/hosts,只修改任一处会导致系统启动异常。首先切换到root用户。

  • /etc/sysconfig/network

用任一款你喜爱的编辑器打开该文件,里面有一行 HOSTNAME=localhost.localdomain (如果是默认的话),修改 localhost.localdomain 为你的主机名。

  • /etc/hosts

打开该文件,会有一行 127.0.0.1 localhost.localdomain localhost 。其中 127.0.0.1 是本地环路地址, localhost.localdomain 是主机名(hostname),也就是你待修改的。localhost 是主机名的别名(alias),它会出现在Konsole的提示符下。将第二项修改为你的主机名,第三项可选。

将上面两个文件修改完后,并不能立刻生效。如果要立刻生效的话,可以用 hostname your-hostname 作临时修改,它只是临时地修改主机名,系统重启后会恢复原样的。但修改上面两个文件是永久的,重启系统会得到新的主机名。

最后,重启后查看主机名 uname -n 。

也可以用hostname 查看

centos7 edit hostname的更多相关文章

  1. centos7修改hostname

    [root@centos7 ~]$ hostnamectl set-hostname prd_web1 # 使用这个命令会立即生效且重启也生效 [root@centos7 ~]$ hostname # ...

  2. CentOS7设置hostname、hosts、静态IP地址、关闭防火墙

    针对新安装或者克隆后的虚拟机配置 1. 设置hostname 方法1: centos7 里面修改hostname的方式有所改变,修改/etc/hosts和/etc/sysconfig/network两 ...

  3. centOS7 修改hostname

    hostnamectl set-hostname 你要修改到的hostname   localectl set-locale LANG=要修改的语言     介绍个Centos 7很不错的教程网站:h ...

  4. centos7修改hostname和hosts

    1.修改/etc/hostname vi /etc/hostname 打开之后的内容是: localhost.localdomain 把它修改成想要的名字就可以,比如:master 保存退出 2.修改 ...

  5. centos7与centos6区别

    CentOS 7 vs CentOS 6的不同   (1)桌面系统[CentOS6] GNOME 2.x[CentOS7] GNOME 3.x(GNOME Shell)(2)文件系统[CentOS6] ...

  6. CentOs7相对于CentOs6的常用命令变化

    比如说防火墙在CentOS6中为 iptables,在CentOS7中变为 firewalld. service iptables stop/start/restart systemctl stop/ ...

  7. centos 修改hostname

    centos修改主机名的正确方法 1 centos6下修改hostname [root@centos6 ~]$ hostname # 查看当前的hostnmae centos6.magedu.com ...

  8. centos7与centos6命令区别

    CentOS 7 vs CentOS 6的不同    (1)桌面系统[CentOS6] GNOME 2.x[CentOS7] GNOME 3.x(GNOME Shell) (2)文件系统[CentOS ...

  9. CentOS7虚拟机克隆,且成功互ping

    第一步:克隆 https://blog.csdn.net/mijichui2153/article/details/80918285 打开VMware,确认已经完成安装配置的CentOS7虚拟机在关闭 ...

随机推荐

  1. js解决跨站点脚本编制问题

    1.前台处理(容易绕过): <script type="text/javascript"> $(document).ready(function(){ var url= ...

  2. js与php中一些相似函数的对比

    一:substr js中:stringObject.substr(start,length)   一个中文算一个字符,一个英文也算一个字符 <script type="text/jav ...

  3. .atitit.web 推送实现解决方案集合(3)----dwr3 Reverse Ajax

    .atitit.web 推送实现解决方案集合(3)----dwr3 Reverse Ajax 1. 原理实现 1 2. Page  增加配置,增加回调函数dwr.engine.setActiveRev ...

  4. Atitit.注重细节还是关注长远??长远优先

    Atitit.注重细节还是关注长远??长远优先 1. 注重细节的误区 1 1.1. 如果连aaa都做不好,那么怎么能够相信你ccc 2 1.2. 一屋不扫何以扫天下??但是扫大街的都是保洁员 2 2. ...

  5. Atitit.故障排除系列---NoClassDefFoundError NoClassDefFoundError

    Atitit.故障排除系列---NoClassDefFoundError  NoClassDefFoundError java.lang.ClassNotFoundException找不到类异常.当应 ...

  6. Intel 5 6 7 8系列芯片组介绍

    Intel 5 6 7 8系列芯片组介绍 Iknow.2015-11-05 22:40|知识编号:122257 操作步骤: [Inetl 5.6.7.8系列芯片组介绍] 芯片组是主板电路的核心.一定意 ...

  7. json对象与json字符串互转方法

    jQuery插件支持的转换方式: 复制代码 代码如下: $.parseJSON( jsonstr ); //jQuery.parseJSON(jsonstr),可以将json字符串转换成json对象 ...

  8. windows phone 切换多语言时,商店标题显示错误的问题

    前段时间,用业余时间写了一款 wp8 app(“超级滤镜”商店,中文地址:英文地址),在多语言的时候,给 app title 和 app tile title 进行多语言时(参考 MSDN),中文商店 ...

  9. form之action的绝对路径与相对路径

    1.当你的form要提交到你自己的站点之外的URL的时候,就采取绝对路径: <form action="http://www.xxx.yyy:zzzz/mmm/nn/kkk.jsp&q ...

  10. systemd启动多实例

    最近用了centos7,启动管理器用的是systemd,感觉很好玩. 1.开机自动启动 新建一个service文件放到/usr/lib/systemd/system/ 比如: [Unit] Descr ...