RHEL / Centos Linux 7:更改和设置Hostname命令

你可以使用以下的任何工具来管理CentOS Linux7的hostnames:

  1. hostnamectl command : 控制系统的hostname,推荐使用这个。
  2. nmtui command : 使用文本用户接口(text user interface (TUI))来控制系统的hostname.
  3. nmcli command : 使用网络管理(NetworkManager)的CLI部分来控制系统的hostname.

hostnames的种类

hostname可以配置为以下几种:
1. Static hostname: 由sysadmin分配. 例如 “server1”, “wwwbox2”, or server42.cyberciti.biz.
2. Transient/dynamic hostname: 由DHCP 或 mDNS server在运行时分配.
3. Pretty hostname: 由sysadmin/end-users分配,并且它是自由形态的UTF8 hostname,用了呈现给用户。例如 “Vivek’s netbook”.

方法1: 使用hostnamectl命令

如何显示现在的hostname设置情况

使用命令hostnamectl 或者 hostnamectl status

$ hostnamectl

结果

   Static hostname: Auto.redhat72.qatest.talend.lan
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 892b6f5b25594ad9b72c89cee1723abf
           Boot ID: 9e399a2bcc1f4a2fb615aed2dce513d3
    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
$ hostnamectl status

结果

   Static hostname: Auto.redhat72.qatest.talend.lan
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 892b6f5b25594ad9b72c89cee1723abf
           Boot ID: 9e399a2bcc1f4a2fb615aed2dce513d3
    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
如何设置hostname
# hostnamectl set-hostname Your-New-Host-Name-Here
# hostnamectl set-hostname "Your New Host Name Here" --pretty
# hostnamectl set-hostname Your-New-Host-Name-Here --static
# hostnamectl set-hostname Your-New-Host-Name-Here --transient
如何删除某个hostname
# hostnamectl set-hostname ""
# hostnamectl set-hostname "" --static
# hostnamectl set-hostname "" --pretty
如何远程设置hostname
# ssh root@server-ip-here hostnamectl set-hostname server1

或者

# hostnamectl set-hostname server1 -H root@192.168.1.42

别的办法就不翻译了,有兴趣请参考
http://www.cyberciti.biz/faq/rhel-redhat-centos-7-change-hostname-command/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值