Linux Find Out My Machine Name/Hostname

How do I find out my server name (machine name) under a Linux operating systems using the command line or bash shell?

You need to use the hostname command or hostnamectl command. Both commands can either set or show the current host, domain or node name of the system.

The procedure to find the computer name on Linux:

  1. Open a command-line terminal app (select Applications > Accessories > Terminal), and then type:
  2. hostname
    cat /proc/sys/kernel/hostname
  3. Press [Enter] key

Linux find hostname using hostnamectl

Type the following command if you are using systemd based distro:
$ hostnamectl

It is possible to filter output using the grep command:
$ hostnamectl | grep 'hostname'
OR simply use the cat command as follows too:
$ cat /proc/sys/kernel/hostname

Linux find computer name using hostname

At the terminal type hostname command:
$ hostname
Sample outputs

  • vivek-laptop : You computer name.
  • : Your dNS domain name.
  • : Your computer name with Fully Qualified Domain Name (FQDN).

To see the domain part of the FQDN (Fully Qualified Domain Name), enter:
$ dnsdomainname
Sample outputs:

How Do I Change My Hostname?

The hostname commands set the host name using the following syntax. Please note that only the super-user / root can change the names. To switch to the root user by typing su – and entering the root password, when prompted.
# hostname
# hostname
# hostnamectl set-hostname

You need to edit /etc/hostname or /etc/sysconfig/network file to set hostname permanently. See our previous FAQ about changing hostname using configuration files.

Getting help

I strongly suggest that your read the man pages by typing the man command:
$ man hostname
$ man hostnamectl

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts