温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

How to Change hostname in Oracle Linux 7

发布时间:2020-08-09 05:31:08 来源:ITPUB博客 阅读:128 作者:eric0435 栏目:建站服务器

在Oracle Linux7中通过修改/etc/sysconfig/network这种方式并不能修改Oracle Linux 7的主机名。为了对Oracle Linux 7修改主机名,可以通过执行以下任何一种方法来实现:
1.使用主机名控制工具(hostnamectl)
2.使用网络管理命令行工具(nmcli)
3.编辑/etc/hostname文件

1.使用主机名控制工具(hostnamectl),它是systemd-hostnamed服务的命令行工具
获取当前主机名:

[root@jytest ~]# hostnamectl status
   Static hostname: jytest
         Icon name: computer
           Chassis: n/a
        Machine ID: 66203d1dd6f54e5da356f986ac82f473
           Boot ID: e8ca08f1d73347358f085a6d0f5ed201
    Virtualization: vmware
  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

修改主机名:

[root@jytest ~]# hostnamectl set-hostname jytest3

重新登录获取当前主机名可以看到主机名已经变成了jytest3

[root@jytest3 ~]# hostnamectl status
   Static hostname: jytest3
         Icon name: computer
           Chassis: n/a
        Machine ID: 66203d1dd6f54e5da356f986ac82f473
           Boot ID: e8ca08f1d73347358f085a6d0f5ed201
    Virtualization: vmware
  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)
获取当前主机名

[root@jytest3 ~]# nmcli general hostname
jytest3

修改主机名并重新启动systemd-hostnamed服务

[root@jytest3 ~]# nmcli general hostname jytest2
[root@jytest3 ~]# systemctl restart systemd-hostnamed

重新登录并检查当前主机名

[root@jytest2 ~]# hostname
jytest2

3.编辑/etc/hostname文件
获取当前主机名

[root@jytest2 ~]# cat /etc/hostname
jytest2

修改主机名

[root@jytest2 ~]# echo "jytest1" > /etc/hostname
[root@jytest2 ~]# cat /etc/hostname
jytest1

重启系统并检查主机名

[root@jytest2 ~]# reboot
[root@jytest1 ~]# hostname
jytest1
[root@jytest1 ~]# cat /etc/hostname
jytest1

引用:How to Configure hostname in Oracle Linux 7 (Doc ID 2049221.1)

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI