ubuntu modifies hostname's methods temporarily or permanently

  • 2020-06-07 05:54:56
  • OfStack

The current ubuntu version is 14.04:

Check the hostname

After connecting to ubuntu via the GNOME terminal, you can directly see the host name in the command prompt, which is usually after the @ symbol, such as root@myvs10ES11en31. You can also use the command in the terminal: hostname or uname -n View the host name.

Temporary modification to hostname

To temporarily change the hostname, run it from the command line: hostname new_hostname

new_hostname can be represented as any valid character. However, this modification only took effect temporarily, and when the system was restarted, hostname was restored. In addition, after modification, the current terminal will not take effect immediately, so a terminal window needs to be reopened.

Permanently modify hostname

Permanent hostname system modifications to hostname only require modifications /etc/hostname Files are sufficient for other linux distributions, hostname /etc/sysconfig/network , so make changes to hostname to distinguish between linux distributions.


root@myvs10d31:~# vim /etc/hostname 
myvs10d31

After modifying hostname, it is suggested to modify /etc/hosts simultaneously:


root@myvs10d31:~# vim /etc/hosts
127.0.0.1    localhost
127.0.1.1    myvs10d31

/etc/hosts stores the corresponding relationship between the domain name and ip. There is no direct relationship between the domain name and the host name. It is possible to specify any corresponding name for one ip.


Related articles: