RHEL7.x version, 3 ways to modify hostname
RHEL7.x no longer uses / etc/sysconfig/network as the configuration file for the hostname, but uses the / etc/hostname file instead, so how do you set the hostname in RHEL7.x? Three ways to set up are described below.
Method 1:
Modify the / etc/hostname file, after which the bash command takes effect.
[root@localhost /] # vim / etc/hostname [root@localhost /] # bash [root@ys /] #
Method 2:
Use the hostnamectl command, and after modification, the bash command takes effect.
[root@localhost /] # hostnamectl set-hostname ys / / set the hostname to ys [root@localhost /] # bash [root@ys /] #
Method 3:
Use the nmcli command to restart systemd-hostnamed.service to take effect after modification
Root@localhost /] # nmcli general hostname ys / / set the hostname to ys [root@localhost /] # nmcli general hostname / / View the current hostname ys [root@localhost /] # systemctl restart systemd-hostnamed.service / / restart to make it effective