1. Temporarily modify the Host Name
Show Host Name:
Zhouhh @ zzhh64 :~ $ Hostname
Zhh64
Modify host name:
Zhouhh @ zzhh64 :~ $ Sudo hostname zzofs
Zhouhh @ zzhh64 :~ $ Hostname
Zzofs
Let's take a look at $ PS1.
Zhouhh @ zzhh64 :~ $ Echo $ PS1
/[/E] 0;/u @/h:/w/a/] $ {debian_chroot: + ($ debian_chroot)}/u @/h:/w/$
@ Symbol followed by/h is the host name.
Why didn't the prompt host name be updated before the command line?
Open a terminal and you will see the update.
Zhouhh @ zzofs :~ $
2. Change the host name permanently.
The above changes are only temporary changes, and the changes are restored after the restart.
Permanent modification on redhat/centos
[Root @ localhost ~] # Cat/etc/sysconfig/network
NETWORKING = yes
HOSTNAME = localhost. localdomain
GATEWAY = 192.168.10.1
Modify the HOSTNAME of the network. The host name is located at the beginning and the domain name is located at the end. The host name is ignored.
[Root @ localhost ~] # Vi/etc/sysconfig/network
NETWORKING = yes
NETWORKING_IPV6 = no
HOSTNAME = gdbk
This is a permanent modification and takes effect after restart. I do not know how to take effect immediately.
To take effect immediately, you can use the first method at the same time.
Deb/ubuntu:
Hostname
Localhost. localdomain
Sudo vi/etc/hostname
Enter the hostname in/etc/hostname.
Zhouhh @ localhost :~ $ Cat/etc/hostname
Zhh64
After the restart, the prompt is changed.
Zhouhh @ zhh64 :~ $
If you do not want to restart, use the hostname command.
3. Other modification methods
Use sysctl to modify kernel. hostname
View:
Zhouhh @ zhh64 :~ $ Sysctl kernel. hostname
Kernel. hostname = zhh64
Modify:
Zhouhh @ zhh64 :~ $ Sudo sysctl kernel. hostname = zzh
Kernel. hostname = zzh
Re-open the shell and change it to the following hostname: zhh
Zhouhh @ zhh64 :~ $ Ping zhh64
PING zhh64 (192.168.11.116) 56 (84) bytes of data.
64 bytes from zhh64 (192.168.11.116): icmp_seq = 1 ttl = 64 time = 0.077 MS
Zhouhh @ zhh64 :~ $ Ping centdev
PING centdev (192.168.12.14) 56 (84) bytes of data.
64 bytes from centdev (192.168.12.14): icmp_seq = 1 ttl = 63 time = 0.726 MS
If it is a small Lan, you can complete the hosts file machine configuration, copy to each machine, and then access it directly using the host name during ssh access.
Zhouhh @ zhh64 :~ $ Ssh centdev
Zhouhh @ centdev's password:
Last login: Wed Feb 3 10:03:09 2010 from 192.168.11.116
[Zhouhh @ centdev ~] $
[Zhouhh @ centdev ~] $ Ifconfig eth0 | grep inet
Inet addr: 192.168.12.14 Bcast: 192.168.12.255 Mask: 255.255.255.0
Inet6 addr: fe80: 21e: c9ff: fe57: 2575/64 Scope: Link