Modify Linux hostname (modify the IP and hostname of the Linux system)

Source: Internet
Author: User

# vi/etc/sysconfig/network
Networking=yes
Hostname=yourname//Modify HOSTNAME in this
Nisdomain=eng-cn.platform.com

2. Modify the name inside the/etc/hosts
# vi/etc/hosts
127.0.0.1 localhost.localdomain localhost
172.17.33.169 yourname//modify hostname in this

3. Finally execute under the terminal:
#hostname * * * * *//***** for modified hostname

The hostname command only changes the hostname temporarily, and the hostname is restored to its original name after reboot. To permanently change the hostname, you need to modify the/etc/sysconfig/network file.

Today found a problem, due to personal habits problem, install the system when the host name is not set up, but used to
# hostname (host name)
Settings, when the login to the system, the host name is set to take effect, because the server is open for a long time, also not too restart, so has not been aware that when the machine is restarted, the host name set using hostname is not recorded in the system files.

View Host name commands
# Uname-n
Qmail.hzhyzg.com

Configuration file
# cat/etc/sysconfig/network
Networking=yes
Hostname=localhost.localdomain

Change the hostname to the hostname of the setting, and always take effect

Modify host name under Linux

Modify Host Name:
1./etc/sysconfig/network
Content:
Networking=yes
HOSTNAME=LH//hostname (no this line?) Then add this line.)
gateway=192.168.1.1
2. Run the command:
#hostname LH
LH is host name
3./etc/hosts
Content:
# don't remove the following line, or various programs
# that require network functionality would fail.
127.0.0.1 localhost localhost.localdomain localhost
Write the second localhost as LH, i.e.:
127.0.0.1 lh localhost.localdomain localhost
However, step 3 is not required. If these three steps are done, whether or not to restart,
Host names will be modified successfully

In the Linux system, the default hostname is Loalhost, if you want to modify your host name, you can use the command: hostname xxx. However, if you are using the X window, you cannot open the xterm after you have modified the hostname with this command. So, a thorough approach is to directly modify the/etc/network file: hostname= xxx, and then restart the computer, the hostname has been modified.

A system that uses DHCP cannot use this method because the hostname is changed to the name provided by the DHCP server when the network is started. What do we do? Since the hostname was brutally modified, then we also rough change back: Edit/ETC/RC, in the end add a line hostname XXX, restart the system is OK.

The following is the IP address of the modified server:

Modify IP available Netconfig or ifconfig eth0 192.168.1.1 255.255.255.0 # do not save IP add dev eth0 192.168.1.1/24 # do not save or vi/etc/sysconfig/net Work-scripts/ifcfg-eth0

Service Network Restart # Restart services

Modify Linux hostname (modify the IP and hostname of the Linux system)

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.