What is my Hostname in Linux? (4 min read)

For most of you, your hostname in Linux is going to be the same as your username. This article will help you figure out your hostname in Linux, and it should be a relatively short article. If this article looks familiar, it’s because it existed at the old site, but with far less information.

Let’s start at the beginning, by learning what a hostname is.

A hostname is generally meant to be a human-readable way to identify a computer. Yes, the computer is truly identified by the associated IP address, but the hostname resolves to that computer. It is meant to be easily remembered instead of having to remember a bunch of IP addresses. Without it, the web (and your own local networks) would be more difficult to navagate.

In many instances, it’s a FQDN (Fully Qualified Domain Name), such as a domain name like linux-tips.us. However, this site doesn’t have a dedicated IP address, so it’s known by a virtual hostname as a FQDN. If the site had been constructed differently, you’d be able to access it with the IP address. For example, https://172.217.10.14 will take you to Google (after some warnings).

So, your hostname in Linux isn’t always going to be the same as your username. For most of the readers here on L-T.us, it will be. You probably don’t really need to worry a whole lot about things like virtual hosts and stuff like that. But, even as a home user, you can make use of this information.

How is it useful? Well, if I want to SSH into my MSI laptop, I don’t have to use the IP address. Not only that, if the IP address changes then I don’t need to look it up. I just connect with something like:

You may notice that I added the .local. You too can just add .local with many distros, in others the default might be something like .localdomain – which you can keep as the default or change it easily enough.

So, let’s figure out how to find your hostname in Linux.

Find your hostname:

Let’s start by cracking open the terminal. You can use your keyboard to do this, just press CTRL + ALT + T and your default terminal should open up.

Now, we can try the following:

Or you can try:

Or you can also try:

As near as I can tell, one of those should work on all major distros. If it none of them work for you, please leave a comment letting me know what does work – helping those who come behind you.

Using Your hostname in Linux:

There are a number of ways that this information can be used. With many distros, as mentioned above, you can add .local to the hostname and just use that instead of IP addresses. Here’s a picture that shows a few examples:

using hostname in Linux
Instead of using the IP address, use the hostname. It’s a pretty handy feature.

There are, of course, other things you can do with this information. Those are just a few examples. The great thing about using a hostname in Linux is that you’ll not have to recall IP addresses. You’ll only need to recall a name – a name that you picked.

You can change your hostname, but that goes beyond the scope of this article. I’d expect to see an article about that in the future! In the meantime, if you can think of any ways that you’d use the hostname, please leave a comment.

Closure:

Thank you, my dear reader, for your viewership. Your comments and feedback keep me motivated and your feedback helps to improve this site. For those who have been keeping track, you can actually now click on large images to see the larger versions. This will only be for future articles, as I’m unlikely to go back through every previous article and change it. But, it was direct feedback that resulted in the change.

If you’d like to contribute, there are a number of ways. You can donate, write an article, unblock ads, buy hosting, and sign up for the newsletter. I promise, I’ll never share your email address with anyone and I won’t send you any spam. Until next time…

Smash a button!
[Total: 3 Average: 5]
Subscribe to Newsletter!
Get notified when new articles are published!
We promise to never share your email!

Author: KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

7 thoughts on “What is my Hostname in Linux? (4 min read)

  1. hostname can be confusing for some i guess, since when i first got into linux and configured network , questions like what is your hostname came up- its not obvious its basically the name of your computer on a network.

    hostname is also mentioned in /etc/hosts file eg:
    $ cat /etc/hosts (05-25 19:05)
    # Static table lookup for hostnames.
    # See hosts(5) for details.
    127.0.0.1 localhost
    ::1 localhost
    127.0.1.1 darkstar.localdomain darkstar

    above is my output on Arch Linux where darkstar is my host name . I’ve seen how did you get your name handle on l’.org i guess we could ask how did you name your PC ?

    1. I’m not sure why I had to manually approve your comment. You should be all set and able to comment without approval – but I’ll run through the settings again shortly.

      That would make a great question. (You can say linux.org, or even link to it if you wanted, I don’t mind at all.)

      Maybe, “How did you pick the hostname (or username) for the computers on your network?” Something like that?

    1. Nice! I didn’t check any of them on Mint, I don’t think. I did my testing in VMs of different OSes. I guess I just kinda assumed that it’d work just fine in Mint as it worked in Lubuntu.

  2. You forgot about hostnamectl:
    hostnamectl [OPTIONS…] COMMAND …

    Query or change system hostname.

    Commands:
    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

    Options:
    -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

    See the hostnamectl(1) man page for details.

Leave a Reply

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