EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home Software Development Software Development Tutorials Software Development Basics CentOS Change Hostname

CentOS Change Hostname

CentOS Change Hostname

Introduction to CentOS Change Hostname

As we know, the Linux operating system supports multiple users to their eco-system. When are we deploying the CentOS operating system without configuring the hostname? Then the instance name will consider as local host. The scope of the communication is restricting to their instance only, i.e. if you want to communicate with the external world, then it will be more difficult. To avoid this condition, we need to change the hostname entry. There are multiple ways to do changes in the hostname.

Note: We need to follow the standard process while defining the hostname. Make sure that you should have a unique name / unique hostname in the network.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax:

hostname [-a|--alias] [-d|--domain] [-f|--fqdn|--long] [-A|--all-fqdns] [-i|--ip-address] [-I|--all-ip-addresses] [-s|--short] [-y|--yp|--nis] vi /etc/hosts

1) hostname: We can use the hostname keyword in the syntax or command. It will accept arguments like different options. We are using the different options in it like an alias, domain name, address, etc. The hostname command will help to get the relevant output in the CentOS environment.

2) vi/etc/hosts: This is an alternative option to edit the hostname. We need to edit the hostname in this file. We need to follow the specific pattern in it. First, we need to add the IP address of the machine. After that, the complete hostname is then the short hostname (without domain).

3) option: We can provide the different flags as the option that is compatible with the hostname command.

How does CentOS change hostname Command Works?

In the working environment, we are having multiple servers, applications, etc. It is very difficult to keep the system name or the IP address of every machine. To overcome this condition, we need to add or set up the hostname to the machine or instance. When any request may come in terms of the hostname, then the host’s file will check (path /etc/hosts). In this file, we have maintained the IP address, FQDN, short hostname. As per the hostname, it will map with the associated IP address.

Below are the list of rules that can be considered while defining the hostname in the system

  • The hostnames should contain the letters, i.e. from a to z.
  • It will also consider as digits also, i.e. from 0 to 9.
  • In a special character, the hostnames will only consider the hyphen character ( – )
  • In a special character, the hostnames will only consider the hyphen character ( . )
  • The hostname will consider the combination of all three rules, but it should be start and end with a letter of the number.
  • The hostname letters should be case insensitive.
  • The length of the hostname is from 2 characters long to 63 characters.
  • The hostname having the proper nomenclature. So that we can easily identify the host.

Below are the lists of options that are compatible with the hostname.

  • -a, –alias: It will help to print the alias name of the host (if used). This option was deprecated, and in some operating systems, it is not be used anymore.
  • -A, –all-fqdns: It will help to display all the FQDN’s associated with the machine.
  • -d, –domain: It will print the name of the DNS domain.
  • -F, –file filename: It will read the hostname from the specified file.
  • -i, –ip-address: It will help to print the network address of the hostname. Suppose the hostname will be resolved, then only this option will works.
  • -I, –all-ip-addresses: It will print all the network addresses of the host.
  • -s, –short: It will print the short hostname. The hostname will print at the initial stage of the dot.
  • -V, –version: It will help to print the version information on the standard output, and it will exit successfully.
  • -y, –yp, –nis: It will print the NIS domain name. If it was set, then only it will display as per this option. Otherwise, it will not display.
  • -h, –help: It will print the helpful information and exit automatically.

Examples

  • CentOS hostname: Get the System Hostname

In the CentOS environment, it is a very simple way to find the hostname.

Command :

hostname

Explanation :

As per the below command, we are able to get the system hostname, i.e. the “mariadb1.db.com”. It will print the complete hostname with a domain name also like “db.com”.

Output :

CentOS Change Hostname 1

  • CentOS hostname: Change the hostname  

In the CentOS environment, we are able to change the hostname of the machine.

Command:

vi /etc/hosts

Explanation :

As per the above “vi” editor, we are able to edit the “/etc/hosts” file. Once we have rebooted the machine. The new hostname entry was enabled.

Output :

Screenshot 1 (a)

CentOS Change Hostname 2

Screenshot 1 (b)

CentOS Change Hostname 3

  • CentOS hostname: Get Associated IP address

In the hostname command, we are able to get the number of IP address associated with the machine.

Command :

hostname -I

Explanation :

As per the above command, we are using the “I” option with the hostname. It will print all the IP address associated with the machine, i.e. the two IP addresses we have seen on the output “10.0.2.15 192.168.56.210”.

Output :

hostname

  • CentOS hostname: Get the Domain Name

In the CentOS environment, we are able to list out the machine domain name.

Command :

hostname -d

Explanation :

As per the above command, we are list out the domain name associated with the machine. The “db.com” domain is associated with it.

Output:

hostname 1

Conclusion

We have seen the uncut concept of the “CentOS change hostname” with the proper example, explanation, and command with different outputs. For the proper communication of all the instances in the network, it is good to set the hostname to every instance. It will help to trace out the machine or the instances through their hostname. Here, no need to remember the machine IP addresses.

Recommended Articles

This is a guide to CentOS Change Hostname. Here we discuss Introduction, How CentOS change hostname Command Works? examples with commands, respectively. You may also have a look at the following articles to learn more –

  1. CentOS Commands
  2. What is CentOS?
  3. What is Remote Access?
  4. Oracle Performance Tuning
All in One Excel VBA Bundle
500+ Hours of HD Videos
15 Learning Paths
120+ Courses
Verifiable Certificate of Completion
Lifetime Access
Financial Analyst Masters Training Program
1000+ Hours of HD Videos
43 Learning Paths
250+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Data Science Bundle
1500+ Hour of HD Videos
80 Learning Paths
360+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Software Development Bundle
3000+ Hours of HD Videos
149 Learning Paths
600+ Courses
Verifiable Certificate of Completion
Lifetime Access
Primary Sidebar
All in One Software Development Bundle3000+ Hours of HD Videos | 149 Learning Paths | 600+ Courses | Verifiable Certificate of Completion | Lifetime Access
Financial Analyst Masters Training Program1000+ Hours of HD Videos | 43 Learning Paths | 250+ Courses | Verifiable Certificate of Completion | Lifetime Access
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more