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 Linux 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 command

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.


The hostnamectl command may be used to query and change the system hostname and related settings on modern Linux distros such as Debian, Ubuntu, CentOS/RHEL, Fedora, Arch Linux and more.

Getting help

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

hostnamectl [OPTIONS...] COMMAND ...
Query or change system hostname.
  status                 Show current hostname settings
  set-hostname NAME      Set system hostname
  set-icon-name NAME     Set icon name for host
  set-chassis NAME       Set chassis type for host
  set-deployment NAME    Set deployment environment for host
  set-location NAME      Set location for host
  -h --help              Show this help
     --version           Show package version
     --no-ask-password   Do not prompt for password
  -H --host=[USER@]HOST  Operate on remote host
  -M --machine=CONTAINER Operate on local container
     --transient         Only set transient hostname
     --static            Only set static hostname
     --pretty            Only set pretty hostname

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 6 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
6 comments… add one
  • sudarshan apite May 28, 2012 @ 10:44

    which command is used for finding the server name…….???????

  • Abdul Dec 11, 2013 @ 16:59

    Which command is used to find OS version by using IP address or hostname?

    • Shankar Damodaran Jun 14, 2015 @ 20:41

      nmap -O

  • mathew Jul 30, 2015 @ 7:23

    how to change my computer name in linux mint 17-
    how to know computer name linuxmint 17

  • Hunter Fuentes Jul 1, 2016 @ 3:44

    How to find the DNS server and search domains

  • Zantar Dec 2, 2017 @ 0:11

    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.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum