Linux Find Out My Machine Name/Hostname

last updated in Categories , , , , ,

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
Linux Find hostname command
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: Vivek Gite

The author is the creator of nixCraft 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.

6 comment

  1. This is incorrect.
    The ‘hostname’ is the ‘shortname’ of the system instance, with the FQDN being the ‘hostname’ with the DNS ‘domain name’ appended (upon using a command to provide it).
    Setting the ‘hostname’ to the FQDN results in “hostname.domainname.domainname” when used (and fails resolution).
    ‘domainame’ is transient, and can change at any time.
    ‘hostname’ is more permanent, referencing the OS ‘instance’ and has nothing to do with the DNS ‘domain’ its currently residing in.

    Still, have a question? Get help on our forum!