Sometimes after installing Ubuntu system, open the command terminal, terminal display of the host name format is ugly, such as I recently bought a cloud VPS in the country.
[Plain]View PlainCopy
- [Email protected]$
- [Email protected]$
For the people who are neat and tidy, see so long also with the system name of the crossbar is annoying, want to go into various ways to eliminate him, fortunately, the command modification on Linux is particularly convenient.
I. About the hostname commandThe hostname command allows you to view and set the name of the current system on Linux 1. View hostname
[Plain]View PlainCopy
- [Email protected]$ hostname
- Vm-1560-ubuntu
2. Set hostname
[Plain]View PlainCopy
- [Email protected]$ hostname newhostname
- Hostname:you must is root to change the host name
This is because modifying the hostname changes the system properties and requires root privileges.
[Plain]View PlainCopy
- [Email protected]$ sudo hostname newhostname
Can.
Ii. about/etc/hostname documentsThis file stores the name of the hostname, which gets the name of the system each time it is started by reading the file.
Iii. about/etc/hostsNetwork host name, you can redirect the IP that the domain name points to by modifying the Hosts file. Before this method can be viewed outside the colorful, as if these two years, haha, you understand.
[Plain]View PlainCopy
- [Email protected]$ sudo vim/etc/hosts
- 127.0.0.1 localhost Vm-1560-ubuntu
127.0.0.1 is the IP of this machine.
Iv. modifying host names1. hostname Modify the system name
[Plain]View PlainCopy
- [Email protected]$ hostname newhostname
2. Modify the/etc/hostname file
[Plain]View PlainCopy
- [Email protected]$ sudo vim/etc/hostname
Change Vm-1560-ubuntu to Newhostname3. Modify the/etc/hosts file
[Plain]View PlainCopy
- [Email protected]$ sudo vim/etc/hosts
Modified before 127.0.0.1 localhost Vm-1560-ubuntu modified 127.0.0.1 localhost newhostname4. Open a new terminal, the system name of the terminal window has been modified
[Plain]View PlainCopy
- [Email protected]$
This method is suitable for Ubuntu systems, such as Ubuntu16.04,ubuntu 16.10. http://blog.csdn.net/sweettool/article/details/70963198
Ubuntu How to modify the host name of the terminal terminal (Modify/etc/hostname file)