CentOS Modify Host Name

Source: Internet
Author: User
Tags ssh access

1. Temporarily modify host name

Display host Name:

[Email protected]:~$ hostname zhh64

Modify Host Name:

[Email protected]:~$ sudo hostname zzofs [email protected]:~$ hostname zzofs

Look at $ps1.

[Email protected]:~$ echo $PS 1/[/e]0;/[email protected]/h:/w/a/]${debian_chroot:+ ($debian _chroot)}/[email protected ]/h:/w/$ @ symbol followed by/h is the hostname.

The prompt before the command line hostname How did not update it?

Re-open a terminal and see the update.

[Email protected]:~$

2. Permanently modify the host name

The above modification is only a temporary change, after the restart is back to the original.

Permanently modified on Redhat/centos

[Email protected] ~]# cat/etc/sysconfig/network networking=yes hostname=localhost.localdomain gateway=192.168.10.1

Modify the hostname entry for the network. The point is preceded by the hostname, and the dot is followed by the domain name. No point is the host name.

[Email protected] ~]# vi/etc/sysconfig/network

Networking=yes Networking_ipv6=no HOSTNAME=GDBK

This is permanently modified and takes effect after reboot. Currently I do not know how to take effect immediately.

To take effect immediately, you can use the first method at the same time.

And there's a change.

/etc/hosts

127.0.0.1 Localhost.localdomain:: 1 Hdirect30 Hdirect30

The part behind the 127.0.0.1.

modified on Deb/ubuntu :

Hostname Localhost.localdomain

sudo vi/etc/hostname

Fill in the hostname directly in the/etc/hostname.

[Email protected]:~$ cat/etc/hostname zhh64

After the reboot, the prompt becomes.

[Email protected]:~$

If you do not want to restart, use the hostname name order.

3. Other modification methods

Modify Kernel.hostname with Sysctl

View:

[Email protected]:~$ sysctl kernel.hostname kernel.hostname = zhh64

Modify:

[Email protected]:~$ sudo sysctl kernel.hostname=zzh kernel.hostname = Zzh

Re-opening the shell becomes the following hostname zhh

[Email protected]:~$

4. Hosts file is not related to hostname modification

Some network articles proposed to modify the hostname also need to modify the Hosts file, in fact, the Hosts file and hostname modification is irrelevant.

Cat/etc/hosts

127.0.0.1 localhost 192.168.11.116 zhh64 192.168.12.14 centdev
# The following lines is desirable for IPV6 capable hosts:: 1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localn ET ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts

The Hosts file is equipped with local hostname/domain name resolution.

As my native IP is 192.168.11.116 name is zhh64. You can access the hostname directly.

[Email protected]:~$ ping zhh64 ping zhh64 (192.168.11.116) bytes of data. Bytes from zhh64 (192.168.11.116): icmp_seq=1 ttl=64 time=0.077 ms

[Email protected]:~$ ping Centdev ping centdev (192.168.12.14) bytes of data. Bytes from Centdev (192.168.12.14): icmp_seq=1 ttl=63 time=0.726 ms

If it is a small local area network, you can complete the Hosts file machine, copy it to each machine, and then access it directly with the host name during SSH access.

[Email protected]:~$ ssh centdev [email protected] ' s password:last login:wed Feb 3 10:03:09 from 192.168.11.116 [[ Email protected] ~]$ [[email protected] ~]$ ifconfig eth0 | grep inet inet addr:192.168.12.14 bcast:192.168.12.255 mask:255.255.255.0 inet6 addr:fe80::21e:c9f F:FE57:2575/64 Scope:link

4. Reference

http://www.ducea.com/2006/08/07/how-to-change-the-hostname-of-a-linux-system/

CentOS Modify Host Name

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.