Hostname linux изменить centos

How to Set or Change a Hostname in CentOS 7

A hostname is simply the name a server goes by on a network. Setting a unique hostname is an excellent way to quickly find and identify different servers on your network.

There are three 3 types of hostnames.

  1. The statichostname is the most important one, and it’s stored in the /etc/hostname file. This hostname is used among machines to identify a particular server.
  2. The pretty hostname got its name because it allows for more characters and punctuation. It’s more user-friendly, but since it uses non-standard characters, it is not permitted for machine code. The pretty hostname is stored in the /etc/machine-info directory.
  3. The transienthostname is one maintained in the Linux kernel. It is dynamic, meaning it will be lost after a reboot. This approach might be useful if you have a minor job requiring a temporary hostname, but you don’t want to risk making a permanent change that might be confusing.

how to set or change hostname in centos guide

  • Server running CentOS 7
  • Access to a user account with root privileges
  • Terminal window (Menu > Applications > Utilities > Terminal)
  • A text editor, like Vim

How to Change Centos Hostname

Step 1: Check Existing Hostname

Before you start, it is advised to check what your current hostname is. Type the following command in the console to find out:

The output should return the static hostname, as well as a list of other information about your network configuration and operating system.

check static hostname on centos

Step 2: Set a New Static Hostname

As CentOS 7 only allows Fully Qualified Domain Names (FQDNs), double-check the hostname you plan to use.

Acceptable values include:

Type in the following command in the terminal:

hostnamectl set-hostname my.new-hostname.server

Note: Make sure to replace my.new-hostname.server with your chosen hostname.

Step 3: Check the Hostname

Next, verify the hostname by using the following command again:

The console should display the new hostname.

Step 4: Edit the /etc/hosts File

Start by opening the hosts file by typing:

In the text editor, look for the line that begins with 127.0.0.1 (the IP address that refers to the system you are working on). It should read:

127.0.0.1 localhost localhost.localdomain localhost 4 localhost4.localdomain4 old.hostname

Change the entry old.hostname to my.new-hostname.server – and spell it the same as in Step 2.

Save the file and exit.

Note: To learn more about hosts file, check out our article on how to edit hosts file on Linux, Windows and Mac.

Читайте также:  Установка пайтон 3 линукс

Step 5: Reboot and Check CentOS 7 machine hostname

Restart your system. Open a console window, and run:

It should display your new hostname.

You can also use your text editor to open and verify your /etc/hostsfile . It should still have your new hostname listed.

Step 6 (Optional): Using a Pretty Hostname

To use a «pretty» hostname type the following command:

hostnamectl set-hostname "My Boss's Hostname"

Make sure you have the quotation marks.

Once that completes, check the hostname:

The console should return a list of information. Check the Static hostname and Pretty hostname lines – they should look like this:

Static hostname: mybossshostname
Pretty hostname: My Boss's Hostname

By putting the hostname in quotes, you’re telling the system to use the complex characters inside the quotes as a pretty hostname.

This enables you to avoid character restrictions for static hostnames.

using a pretty name on centos

But you still need a FQDN hostname for the machine to understand. Fortunately, CentOS is smart enough to remove or change any unacceptable characters and render the static hostname automatically.

Step 7 (Optional): Setting a Transient Hostname

Fist, open the console and type the following:

sudo hostnamectl -transient set-hostname temporary.hostname

You can check the hostname in the same way you did earlier, with the hostnamectl or hostnamectl status command.

This change will last until you reboot the machine.

You can use this command with any type of hostname (Static, Pretty, or Transient) as an option with the double-hyphen.

Just use the double-hyphen to indicate what you want:

sudo hostnamectl --prettyset-hostname "Pretty Hostname"
sudo hostnamectl --staticset-hostname temporary.hostname

Note: If you are using CentOS 8, please refer to our guide on how to change or set the hostname on CentOS 8 / RHEL 8.

To set or change a hostname in CentOS 7 is fairly straightforward.

If you are a more advanced user, you can try out other methods as well. One way is editing the /etc/hostname file with a text editor. Alternatively, you can run the nmtui tool at the command prompt, which will launch a little graphical tool to change the hostname.

A guide on how to change or set the hostname is also available for other Linux distributions like Ubuntu 18.04.

Sofija Simic is an experienced Technical Writer. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.

If you decide to change your hostname, you have multiple available options to do so. Follow the methods in.

Learn The Simple Way How to Change Hostname on Ubuntu 18.04. Multiple options, including using Linux command.

DNS cache can be corrupted for a number of different reasons, including network attacks or viruses. When that.

The hosts file in Windows, Mac, or Linux maps hostnames to IP addresses. This could be in an intranet, like a.

Источник

Как изменить имя хоста в CentOS 7 навсегда

С появлением CentOS 7 изменился синтаксис многих команд этой операционной системы. Я уже писал ранее как сменить консоль в CentOS, теперь это две разные инструкции для CentOS 6 и CentOS 7. В этой статье я расскажу как изменить имя хоста в CentOS 7 & RHEL 7.

Чтобы изменить имя хоста навсегда в CentOS 7 воспользуйтесь следующей командой:

# hostnamectl set-hostname New_HostName

где New_HostName — это новое имя хоста.

Читайте также:  Управление политикой безопасности astra linux через консоль

В некоторых случаях, если вы используете виртуальный сервер, вам также потребуется отключить изменение hostname при загрузке с помощью команды:

# scarletctl disable set-hostname

Перезапуск сервиса systemd-hostnamed

Чтобы все изменения вступили в силу желательно перезапустить службу (сервис) systemd-hostnamed:

# systemctl restart systemd-hostnamed

Как проверить имя хоста в CentOS 7

Чтобы увидеть имя хоста сервера в CentOS 7 воспользуйтесь командой hostnamectl:

Вы увидите примерно следующее:

# hostnamectl status Static hostname: sitename.tld Icon name: computer-vm Chassis: vm Machine ID: ce4cc7f6d67d0056a8a68503a37d39ee Boot ID: 58599810ff8e4d6b882f4181b616ff46 Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-327.10.1.el7.x86_64 Architecture: x86-64

Благодарности

При написании статьи были использованы следующие источники:

Источник

How to Change or Set Hostname on CentOS 8 / RHEL 8

The hostname of a machine is a label that differentiates one system from another on a single network.

During the installation of Centos 8, either the admin defines a hostname or one is automatically created. The assigned system name is not always easy to remember. Later, if you add more machines to the network, you may want to organize hostnames.

In this tutorial, learn how to change the hostname on Centos 8 / RHEL.

tutorial on setting or changing the hostname on centos 8

  • CentOS 8 / RHEL system
  • A user with Sudo or root permissions
  • Access to a terminal or command line
  • Any built-in text editor

Understanding the Types of Hostnames

There are three classes of hostnames:

  • The traditional hostname, located at /etc/hostname. The guide focuses on this type.
  • A human-readable hostname that allows special characters (e.g., pnap’s server). The system only uses it as a presentation to the user. It is located in the /etc/machine-info directory.
  • A changeable hostname that the Linux kernel maintains. By default, it is the same as static, but DHCP and mDNS can change it, or you can change it manually.

The static hostname is defined by default as localhost, while the other two need to be specified separately.

How to Display Current Hostname

To check a machine’s hostname, open the terminal and enter:

Checking CentOS hostname in the terminal.

Our virtual machine has the default hostname, localhost.localdomain.

Check out our article on the hostname command to learn more about this command and how to use it.

Another way to check the static hostname and get more details about the machine is to use the hostnamectl command:

Change Hostname on CentOS 8 / RHEL without Restarting the System

In some circumstances, rebooting a machine is not an option. There are multiple methods to change the hostname on CentOS 8 or RHEL without having to restart the machine.

Select the option you prefer and then log out and log back in to make sure the changes have taken effect.

Note: It does not matter if you are creating virtual machines or booting physical servers, always assign hostnames in a logical manner. The maximum number of characters you can use is 64.

Use hostnamectl to Change Hostname

The hostnamectl tool allows you to set all classes of hostnames. The command works on other Linux distributions as well, not only CentOS / RHEL.

Set Static Hostname with hostnamectl

The syntax to set a static hostname with hostnamectl is:

sudo hostnamectl set-hostname host.domain

For example, we will change the hostname to vm1.phoenixnap.com:

sudo hostnamectl set-hostname vm1.phoenixnap.com

The terminal returns a new line. Use one of the two methods we mentioned to verify if the hostname was changed:

Читайте также:  Swap files in linux

Using hostnamectl to change a hostname on CentOS 8

Set Pretty Hostname with hostnamectl

To modify the pretty hostname, append —pretty to the command:

sudo hostnamectl set-hostname "New Pretty Hostname" --pretty
sudo hostnamectl set-hostname "PNAP's Test VM" --pretty

Enter hostnamectl to verify the changes:

Set pretty hostname CentOS 8 with hostnamectl

Set Transient Hostname with hostnamectl

Following the pattern from the previous example, set a transient hostname by adding —transient to the command.

sudo hostnamectl set-hostname testvm1.phoenixnap.com

Check the changes with hostnamectl :

Using hostnamectl to set the transient hostname in CentOS 8

Use nmtui to Change Hostname

Launch the NetworkManager TUI with the nmtui command to change the hostname. This is not the primary function of the tool, but it allows users to set a new hostname.

1. In a terminal window, enter:

The tool opens in the same window.

2. Select Set system hostname using the keyboard arrows.

Using nmtui to set the hostname in CentOS 8

3. Enter the desired hostname and select .

Entering the hostname in the nmtui tool in CentOS 8

4. Enter your password if prompted, and confirm the changes.

5. Quit the tool.

6. You may need to restart the system-hostnamed to apply the changes:

sudo systemctl restart system-hostnamed

You have successfully changed the hostname on your CentOS 8 or RHEL machine.

Use nmcli to Change Hostname

The nmcli tool is also used to control the NetworkManager, but without the GUI.

The command to change the hostname with nmcli is:

sudo nmcli g hostname newhostname.domain
sudo nmcli g hostname vm.phoenixnap.com

Restart sytemd-hostanmed to apply the changes:

sudo systemctl restart system-hostnamed

Check the hostname using one of the methods we mentioned previously. In this case, we will use nmcli to check the hostname:

Set Hostname by Editing /etc/hostname File (Restart Required)

If you are accustomed to editing system files, change the hostname by making the following changes:

1. Open the /etc/hostname file using your preferred text editor. In this example, we will use nano:

2. Change the current hostname to the desired hostname.

3. Save the changes and exit the editor.

4. Restart the system to apply the changes.

Changing the hostname on CentOS 8 or RHEL by editing the hostname file in a text editor.

Note: For more details on how to change the hostname other Linux systems, refer to our tutorials How To Change Hostname On CentOS 7, How To Change Hostname On Ubuntu 18.04, How To Change Hostname On Ubuntu 20.04 or How to Change Hostname in Debian 10.

This tutorial explained different options to change the hostname on CentOS 8 /RHEL. Select the system name you prefer, and quickly modify the hostname on your CentOS 8 system.

Goran combines his leadership skills and passion for research, writing, and technology as a Technical Writing Team Lead at phoenixNAP. Working with multiple departments and on various projects, he has developed an extraordinary understanding of cloud and virtualization technology trends and best practices.

The LAMP stack consists of open-source software required for web development. Install and configure the LAMP.

Learn The Simple Way How to Change Hostname on Ubuntu 18.04. Multiple options, including using Linux command.

The hosts file in Windows, Mac, or Linux maps hostnames to IP addresses. This could be in an intranet, like a.

This technical guide is for users who already have a server running the CentOS 7 operating system on a.

Источник

Оцените статью
Adblock
detector