centos

centos hostname设置步骤

小樊
41
2025-09-24 12:08:53
栏目: 智能运维

CentOS Hostname Setting Steps

Hostname is a critical identifier for Linux systems, used by applications and services to recognize the machine. Below are detailed steps to configure hostnames in CentOS, categorized by version and method.

1. View Current Hostname

Before making changes, verify the existing hostname using one of these commands (works for all CentOS versions):

hostname       # Displays the current transient hostname
hostnamectl    # Shows static, transient, and pretty hostnames (CentOS 7+)

2. Temporary Hostname Change (CentOS 6/7/8)

This change takes effect immediately but resets after a reboot. Use it for testing:

sudo hostname new-hostname  # Replace "new-hostname" with your desired name

Verify with hostname or hostnamectl.

3. Permanent Hostname Change

For a lasting change, modify system configuration files and update the /etc/hosts file to avoid resolution issues.

CentOS 6

CentOS 7/8

4. Verify Hostname Change

After applying changes (temporary or permanent), confirm the new hostname with:

hostnamectl     # Displays static, transient, and pretty hostnames
hostname        # Shows the current transient hostname
cat /etc/hostname  # Confirms the static hostname (CentOS 7+)

Key Notes

By following these steps, you can safely configure and manage hostnames in CentOS systems of any version.

0
看了该问题的人还看了