Lanyiyun: Tutorial on installing Oracle11 under CentOS7

In Linux systems, hostname related commands are used to view and set the host name. A hostname is a unique name used to identify a computer on a network. The following are some commonly used hostname related commands:

1. View the current hostname:

hostname

2. View the complete host name (including domain name):

hostname -f

3. Set the host name (effective temporarily, invalid after restart):

sudo hostname newhostname

4. Set the host name permanently (applicable to systems using systemd such as Ubuntu):
edit  /etc/hostnamethe file, change the contents to the new host name, save and exit.

5. Permanently set the host name (applicable to systems using sysvinit such as CentOS):
Edit  /etc/sysconfig/networkthe file, set it  HOSTNAMEto the new host name, save and exit.

6. Make the newly set hostname take effect:
In Ubuntu, use the following command:

sudo service systemd-hostnamed restart

In CentOS, use the following command:

sudo service network restart

or

sudo reboot

7. Modify the hosts file (optional):
In order to ensure that the host name can be resolved locally, you can edit  /etc/hoststhe file and add a line:

127.0.0.1   newhostname

This can avoid some local access problems.

Using these hostname-related commands, you can easily view and set the hostname of your Linux system. Please note that before changing the hostname, make sure you understand its impact on the system and network, and ensure that the corresponding configuration files are modified correctly to avoid problems.

Guess you like

Origin blog.csdn.net/tiansyun/article/details/133363958