Redhat7.2 在安装的时候,会默认生成主机名:localhost. 那么如何修改成自己想要的自己名?

//格式为:用户名@主机名

比如: [root@localhost ~]#  修改成[root@xiaolyu ~]#

我的目前已经是[root@xiaolyu ~]# 主机名(hostname)为xiaolyu ,可以修改为lyu。

方法一: 用图像界面修改(永久性修改)

在终端输入命令 nutui :[root@xiaolyu ~]# nmtui

进入如下图形界面:

选择第三行:Set system hostname

按回车键,进入:

然后直接进行编辑修改即可:

选中《OK>按回车键即可。

OK 即可!

重新打开一个新的终端,既可以发现主机名已经修改过来了:

[root@lyu ~]#

方法二:用命令行模式修改主机名:(永久修改,静态模式)

比如这里讲lyu改成xiaolyu:

[root@lyu ~]# hostnamectl
Static hostname: lyu
Icon name: computer-vm
Chassis: vm
Machine ID: 41395788ce5a4b3f93805203ebf82245
Boot ID: 02c90c2e76784d1293358ab6bc509f78
Virtualization: vmware
Operating System: Red Hat Enterprise Linux Server 7.2 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64

[root@lyu ~]# hostname --help
Usage: hostname [-b] {hostname|-F file} set host name (from file)
hostname [-a|-A|-d|-f|-i|-I|-s|-y] display formatted name
hostname display host name

{yp,nis,}domainname {nisdomain|-F file} set NIS domain name (from file)
{yp,nis,}domainname display NIS domain name

dnsdomainname display dns domain name

hostname -V|--version|-h|--help print info and exit

Program name:
{yp,nis,}domainname=hostname -y
dnsdomainname=hostname -d

Program options:
-a, --alias alias names
-A, --all-fqdns all long host names (FQDNs)
-b, --boot set default hostname if none available
-d, --domain DNS domain name
-f, --fqdn, --long long host name (FQDN)
-F, --file read host name or NIS domain name from given file
-i, --ip-address addresses for the host name
-I, --all-ip-addresses all addresses for the host
-s, --short short host name
-y, --yp, --nis NIS/YP domain name

Description:
This command can get or set the host name or the NIS domain name. You can
also get the DNS domain or the FQDN (fully qualified domain name).
Unless you are using bind or NIS for host lookups you can change the
FQDN (Fully Qualified Domain Name) and the DNS domain name (which is
part of the FQDN) in the /etc/hosts file.

[root@lyu ~]# hostnamectl --static set-hostname xiaolyu

再次打开一个新终端,可以发现@后面的用户名已经修改。

[root@lyu ~]# hostname
xiaolyu
[root@lyu ~]# hostnamectl
Static hostname: xiaolyu
Icon name: computer-vm
Chassis: vm
Machine ID: 41395788ce5a4b3f93805203ebf82245
Boot ID: 02c90c2e76784d1293358ab6bc509f78
Virtualization: vmware
Operating System: Red Hat Enterprise Linux Server 7.2 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
[root@lyu ~]#

(init6或者reboot之后也可以,但是比较麻烦)。

而且是永久修改。

如何让@后面显示的主机名也跟着变呢?重启! reboot或者init 6

再次查看:

搞定!

修改主机名的方法,还有很多,后续我会继续补充

最新文章

  1. [AlwaysOn Availability Groups]排查:AG超过RPO
  2. MySQL判断字段值来确定是否插入新记录
  3. CSS常用样式及示例
  4. Spring Bean配置默认为单实例 pring Bean生命周期
  5. Spring配置概述
  6. 利用TraceSource写日志
  7. Spring MVC中前后台数据传输小结
  8. Android微信朋友圈全文、收起功能
  9. 前端css要加的一些
  10. 【爆料】-《亚伯大学毕业证书》Aber一模一样原件
  11. [OC] UIcollectionView 与 UIcollectionViewCell 的使用
  12. Android/Linux boot time分析优化
  13. 【Java基础】Java注解简单入门
  14. opencv学习之路(31)、GrabCut & FloodFill图像分割
  15. 系统编码、文件编码与python系统编码
  16. SQLServer将服务器A表写到服务器B表
  17. OpenStack的基本概念与架构图
  18. PHP zhuaq
  19. 【枚举】AtCoder Regular Contest 095 C - Symmetric Grid
  20. Android图片加载框架最全解析(七),实现带进度的Glide图片加载功能

热门文章

  1. java 调用 C# 类库搞定,三步即可,可以调用任何类及方法,很简单,非常爽啊
  2. [.NET领域驱动设计实战系列]专题五:网上书店规约模式、工作单元模式的引入以及购物车的实现
  3. UWP的一种下拉刷新实现
  4. CSS:谈谈栅格布局
  5. Asp.Net MVC中使用ACE模板之Jqgrid
  6. TW2015技术雷达中文版发布
  7. HTML5文件上传插件 Huploadify V2.1发布
  8. Senparc.Weixin.MP SDK 微信公众平台开发教程(十六):AccessToken自动管理机制
  9. Vuejs注意点
  10. NSDate NSString相互转化