banner



How To Set Hostname In Centos 7

Introduction

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

In that location are 3 iii 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 information technology allows for more characters and punctuation. It's more user-friendly, only since it uses non-standard characters, it is not permitted for motorcar 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 volition exist lost later a reboot. This approach might be useful if you lot have a minor chore requiring a temporary hostname, merely you don't want to run a risk making a permanent change that might be confusing.
how to set or change hostname in centos guide

Prerequisites

  • Server running CentOS vii
  • 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: Cheque Existing Hostname

Before y'all start, it is advised to check what your electric current hostname is. Type the post-obit command in the console to find out:

          hostnamectl        

The output should render the static hostname, as well as a list of other information nearly your network configuration and operating organisation.

check static hostname on centos

Step 2: Fix a New Static Hostname

Every bit CentOS seven only allows Fully Qualified Domain Names (FQDNs), double-check the hostname y'all program to use.

Acceptable values include:

  • Lower-case letters a to z
  • Numbers 0 to nine
  • Periods and hyphens
  • Hostnames must exist betwixt 2 and 63 characters
  • Hostnames must offset and stop with a number or letter of the alphabet

Type in the post-obit control in the last:

          hostnamectl set-hostname my.new-hostname.server        

Annotation: Brand sure to replace my.new-hostname.server with your chosen hostname.

Pace three: Check the Hostname

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

          hostnamectl        

The console should brandish the new hostname.

Step 4: Edit the /etc/hosts File

Starting time by opening the hosts file by typing:

          sudo vim /etc/hosts        

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

          127.0.0.i  localhost localhost.localdomain localhost 4 localhost4.localdomain4 old.hostname        

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

Salvage the file and exit.

Pace 5: Reboot and Check CentOS vii machine hostname

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

          hostnamectl        

It should display your new hostname.

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

Stride 6 (Optional): Using a Pretty Hostname

To apply a "pretty" hostname blazon the following command:

          hostnamectl set-hostname "My Boss'due south Hostname"        

Brand sure y'all take the quotation marks.

Once that completes, cheque the hostname:

          hostnamectl status        

The console should return a list of information. Cheque the Static hostname and Pretty hostname lines – they should wait similar this:

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

By putting the hostname in quotes, you lot're telling the arrangement to employ the complex characters within the quotes as a pretty hostname.

This enables yous to avert character restrictions for static hostnames.

using a pretty name on centos

Just you still need a FQDN hostname for the machine to empathise. Fortunately, CentOS is smart plenty to remove or change any unacceptable characters and return the static hostname automatically.

Step seven (Optional): Setting a Transient Hostname

Fist, open the console and blazon the following:

          sudo hostnamectl -transient ready-hostname temporary.hostname        

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

This change will terminal until yous reboot the car.

You can employ this control with any type of hostname (Static, Pretty, or Transient) every bit an choice with the double-hyphen.

Merely use the double-hyphen to bespeak what you want:

          sudo hostnamectl --prettyset-hostname "Pretty Hostname"        

or

          sudo hostnamectl --staticset-hostname temporary.hostname        

Conclusion

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

If you are a more avant-garde user, you tin try out other methods too. One way is editing the /etc/hostname file with a text editor. Alternatively, y'all 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 gear up the hostname is as well available for other Linux distributions like Ubuntu 18.04.

Was this commodity helpful?

Yes No

How To Set Hostname In Centos 7,

Source: https://phoenixnap.com/kb/how-to-set-or-change-a-hostname-in-centos-7

Posted by: tomourt1974.blogspot.com

0 Response to "How To Set Hostname In Centos 7"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel