Oracle Linux 7 修改 hostname

Linux修改hostname的常用操作方法是——手工在/etc/sysconfig/network中追加"HOSTNAME=xxxxx"并重启系统,这个方法在Oracle Linux 7中是不生效的。
那么在Oracle Linux 7中怎么配置hostname?
来源于:
How to Configure hostname in Oracle Linux 7 (Doc ID 2049221.1)

解决方案:
请使用如下三种方法的任意一种来修改Oracle Linux 7中的主机名
1. use hostname control utility: hsotnamectl
2. use NetworkManager command line tool: nmcli
3. edit /etc/hostname file directly (a reboot afterwards is required)

1. Use hsotnamectl which is a command-line client to systemd-hostnamed service


Get current hostname status:

[root@localhost ~]# hostnamectl status
   Static hostname: localhost.localdomain
  Operating System: Oracle Linux Server 7.1
       CPE OS Name: cpe:/o:oracle:linux:7:1
            Kernel: Linux 3.8.13-55.1.6.el7uek.x86_64
      Architecture: x86_64


Set hostname:

[root@localhost ~]# hostnamectl set-hostname oraclelinux.oracle.com
[root@localhost ~]#


Re-login terminal session:

[root@oraclelinux ~]# hostnamectl status
   Static hostname: oraclelinux.oracle.com
  Operating System: Oracle Linux Server 7.1
       CPE OS Name: cpe:/o:oracle:linux:7:1
            Kernel: Linux 3.8.13-55.1.6.el7uek.x86_64
      Architecture: x86_64

2. nmcli


Check current hostname:

[root@localhost ~]# nmcli general hostname
localhost.localdomain


Modify hostname and restart ystemd-hostnamed service:

[root@localhost ~]# nmcli general hostname oraclelinux.oracle.com
[root@localhost ~]# systemctl restart systemd-hostnamed


Re-login terminal session:

[root@oraclelinux ~]# hostname
oraclelinux.oracle.com


3. Edit /etc/hostname


View current content:

[root@localhost ~]# cat /etc/hostname
localhost.localdomain


Replace file content with new hostname:

[root@localhost ~]# echo "oraclelinux.oracle.com" > /etc/hostname
[root@localhost ~]# cat /etc/hostname
oraclelinux.oracle.com


Restart system and verify:

[root@oraclelinux ~]# hostname
oraclelinux.oracle.com

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

转载于:http://blog.itpub.net/12707874/viewspace-2140997/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值