• Home
  • Subscribe
  • Contribute Us
    • Share Your Interview Experience
  • Contact Us
  • About
    • About CSEstack
    • Campus Ambassador
  • Forum & Discus
  • Tools for Geek
  • LeaderBoard
CSEstack

What do you want to Learn Today?

  • Programming
    • Tutorial- C/C++
    • Tutorial- Django
    • Tutorial- Git
    • Tutorial- HTML & CSS
    • Tutorial- Java
    • Tutorial- MySQL
    • Tutorial- Python
    • Competitive Coding Challenges
  • CSE Subject
    • (CD) Compiler Design
    • (CN) Computer Network
    • (COA) Computer Organization & Architecture
    • (DBMS) Database Management System
    • (DS) Data Structure
    • (OS) Operating System
    • (ToA) Theory of Automata
    • (WT) Web Technology
  • Interview Questions
    • Interview Questions- Company Wise
    • Interview Questions- Coding Round
    • Interview Questions- Python
    • Interview Questions- REST API
    • Interview Questions- Web Scraping
    • Interview Questions- HR Round
    • Aptitude Preparation Guide
  • GATE 2022
  • Linux
  • Trend
    • Full Stack Development
    • Artificial Intelligence (AI)
    • BigData
    • Cloud Computing
    • Machine Learning (ML)
  • Write for Us
    • Submit Article
    • Submit Source Code or Program
    • Share Your Interview Experience
  • Tools
    • IDE
    • CV Builder
    • Other Tools …
  • Jobs

7 Linux Hostname Commands with Example | You should Know

Aniruddha Chaudhari/11028/0
Linux

The hostname is very important Linux command that you can find useful many times. If you are reading this article, for sure, you are using Linux system. Here you can get all the Linux hostname commands that you need to run every day.

Table of Content:

  • Hostname Command Syntax
  • Important Hostname Commands Examples:
    • How to find the hostname in Linux?
    • How to get the IP address from hostname?
    • What is the command to get the DNS of the system?
    • What is the command to get the FQDN of the system?
    • How to find the alias of the hostname?
    • What is the command to change the hostname?
    • How to make the hostname changes permanent?
  • Hostname help command

The host is nothing but your Linux system. And hostname is identity given to your system.

The hostname is useful when you want to connect your system to another system. To identify each system on the network, every system has been given hostname as identity.  Hostname of the system is unique over the connected network.

Hostname command is used to get the system hostname as well as the DNS (Domain Name System) of the system.

Command hostname syntax:

Hostname command has its syntax.

hostname [option]

The syntax for changing the hostname:

hostname [options] [new_host_name]

7 Linux Hostname Commands | You should know…

Each of the commands is explained in required detail for better understanding.

1. What is the command to find hostname in Linux?

Use the hostname command without any option.

hostname

It is also called as the domain name of the system.

2. What is the Linux command to get the IP address from hostname without ifconfig?

As I told you earlier, the hostname is unique over the connected network, there is corresponding IP address associated with hostname.

The hostname needs to resolve to get IP address which can be inferred from the hostname command along with -i and -I option.

hostname -i

Or, you can use…

hostname -I

You can also find the IP address of the Linux system using ifconfig. But, command ifconfig gives a large list of IP addresses. If you need only IP address you can just use hostname -i command. It’s easy.

3. How to get the DNS name of the system?

Use -d option to get the DNS name of the system.

hostname -d

Above command only give DNS name. It does not specify the exact location of the system in a hierarchy of DNS. To locate the exact location, you need a Fully qualified domain name (FQDN).

4. How to get the FQDN of the system?

Use -f option with hostname command.

hostname -f

This command will return the complete and exact location of the system in DNS hierarchy.
To see all the FQDN of the system use option -A.

hostname -A

5. How to get the alias name of the host?

There can be an aliased name for your hostname. Use -a flag with hostname command.

hostname -a

Additional read: Linux Command to check the Serial Number

Now,

6. What is the Linux command to change hostname?

It is an easy and simple command.

sudo hostname <new_hostname>

You need super privilege for changing the hostname of the system.

If you try to get the IP address corresponds to the hostname, you may get some time error as…

hostname: Temporary failure in name resolution

Hostname command changes only persist until you reboot your Linux system.

7. How to make the hostname changes permanent?

There is a way to make the changes permanent if you wish.

Use a command hostnamectl.

hostnamectl

Before you leave…

You can explore and find more hostname commands using help option.

Hostname help command:

There are many other options you can use with hostname. You can get all the options by running a command hostname -h.

hostname -h

All the above-mentioned commands are tested on Ubuntu system and will work with any other Linux distribution.

Related Article:

  • 6 Linux Commands to Edit File

That’s all from this quick post on Linux hostname command and examples. These are the very useful command related to the hostname. If you have any query related to the Linux command, let’s discuss in the comment.

hostnamelinux cmd
Aniruddha Chaudhari
I am complete Python Nut, love Linux and vim as an editor. I hold a Master of Computer Science from NIT Trichy. I dabble in C/C++, Java too. I keep sharing my coding knowledge and my own experience on CSEstack.org portal.

Your name can also be listed here. Got a tip? Submit it here to become an CSEstack author.

Leave a Reply Cancel reply

Make Your Linux Run Faster

Linux- Remove Old Kernels

Linux- Auto-Remove Unused Packages

Linux Commands

Linux- Most Useful Commands

Linux- LS command [Tool]

Linux- 7 Hostname Commands

Linux- Text Search in Terminal

Linux- File Permission [Chmod Calculator]

Linux- Check Free Memory in Ubuntu

Linux- Find Total Size of the Directory

Linux- Mount/Umount USB Drive

Linux- Change VNC Password

Linux- Get Serial Number (dmidecode)

Linux- Execute Shell Script

Linux Tools

5 Free Linux screenshot tools

Vim Editor Tricks

Vim- Setting Vim of Programming

Vim- 6 Commands to Edit File

Vim- Case-Sensitive Search

Vim- How to Create Function?

© 2022 – CSEstack.org. All Rights Reserved.

  • Home
  • Subscribe
  • Contribute Us
    • Share Your Interview Experience
  • Contact Us
  • About
    • About CSEstack
    • Campus Ambassador
  • Forum & Discus
  • Tools for Geek
  • LeaderBoard