How to Change hostname in Oracle Linux 7
You cannot change the hostname of Oracle Linux7 by modifying / etc/sysconfig/network in Oracle Linux7. To change the hostname for Oracle Linux 7, you can do this by performing any of the following methods:
1. Use the hostname control tool (hostnamectl)
two。 Use the network management command line tool (nmcli)
3. Edit / etc/hostname file
1. Use the hostname control tool (hostnamectl), which is the command line tool for systemd-hostnamed services
Get the current hostname:
[root@jytest ~] # hostnamectl status Static hostname: jytest Icon name: computer Chassis: n Machine ID a Machine ID: 66203d1dd6f54e5da356f986ac82f473 Boot ID: e8ca08f1d73347358f085a6d0f5ed201 Virtualization: vmware Operating System: Oracle Linux Server 7.1CPE OS Name: cpe:/o:oracle:linux:7:1 Kernel: Linux 3.8.13-55.1.6.el7uek.x86_64 Architecture: x86 * 64
Modify the hostname:
[root@jytest ~] # hostnamectl set-hostname jytest3
Log in again to get the current hostname and you can see that the hostname has become jytest3
[root@jytest3 ~] # hostnamectl status Static hostname: jytest3 Icon name: computer Chassis: n Machine ID a Machine ID: 66203d1dd6f54e5da356f986ac82f473 Boot ID: e8ca08f1d73347358f085a6d0f5ed201 Virtualization: vmware Operating System: Oracle Linux Server 7.1CPE OS Name: cpe:/o:oracle:linux:7:1 Kernel: Linux 3.8.13-55.1.6.el7uek.x86_64 Architecture: x86 * 64
two。 Use the network management command line tool (nmcli)
Get the current hostname
[root@jytest3 ~] # nmcli general hostnamejytest3
Modify the hostname and restart the systemd-hostnamed service
[root@jytest3 ~] # nmcli general hostname jytest2 [root@jytest3 ~] # systemctl restart systemd-hostnamed
Log in again and check the current hostname
[root@jytest2 ~] # hostnamejytest2
3. Edit / etc/hostname file
Get the current hostname
[root@jytest2 ~] # cat / etc/hostnamejytest2
Modify hostname
[root@jytest2 ~] # echo "jytest1" > / etc/hostname [root@jytest2 ~] # cat / etc/hostnamejytest1
Restart the system and check the hostname
[root@jytest2 ~] # reboot [root@jytest1 ~] # hostnamejytest1 [root@jytest1 ~] # cat / etc/hostnamejytest1
Reference: How to Configure hostname in Oracle Linux 7 (Doc ID 2049221.1)