Use Your Hostname With SSH Instead Of Your IP Address – In Ubuntu

Today’s article will show you how to use your hostname with SSH instead of your IP address. This should actually be a very short article, like really short. We’re only using Ubuntu for this example, because it consistently uses the .local for your hostname. This will work with any distro that does that.

If you don’t know what SSH is, it’s ‘Secure Shell’ and is a way of connecting to remote computers. I’ve written many articles about SSH. Go ahead. Click that link and have a browse around. This will be a short article because I’ve already written a good amount of material. I’m trusting you to search for things you don’t already know.

You’re also going to need to know your hostname. To do that, read this article:

What is my Hostname in Linux?

You’ll need that hostname information because that’s how you’ll be using your hostname with SSH. I’m going to assume you already know the IP address, because that’s what you’d have been using for SSH instead of using your host name this entire time.

With all that in mind, let’s just get to it…

Use Your Hostname With SSH:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

Now, again, I’m going to assume you know the IP address and that’s how you’ve been connecting to the device with SSH. I’m going to assume that you read the above link, learning how to find your hostname.

So, with that in mind, login to your remote Ubuntu (or official Ubuntu flavors) computer using your IP address. Next, find your hostname. You can just use the hostname command, to make it easier.

Now that you have your hostname, add .local to it. This works because it’s on your local network. If you had a VPS somewhere, you’d just use the FQDN (like example.com) to connect. Then, with that hostname information in hand, exit your SSH session with exit and try logging in with the hostname.

So, if your computer was called ‘mydevice’ you would connect to it with:

That’s it. Just put your hostname in front of .local and you should be able to use your hostname with SSH. This will work for other distros, of course. However, I’ve only verified it with official Ubuntu flavors. So, that’s the caveat should you try this with other distros.

Closure:

See? I told you that this would be a short article. It really doesn’t need to be longer and I’ve padded it more than enough. Seriously, this one could have been so much shorter!

This site could really use a better author and an editor! Alas, you get what you get and that’s just me at the moment. Do feel free to offer to help. I have thought about doing more of these fairly short articles, as there are some great subjects that really don’t need an 800+ word article.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Change Your Hostname

In today’s article, we’re going to learn how to change your hostname in Linux. It’s a pretty easy article to follow along with, so even if you’re a beginner you can follow along. If you’re an advanced user, you probably already know how to do this. If not,  you will now.

So, what is your hostname? Basically, it’s the name of your computer (generally speaking). You login as <your_username> to a computer referred to by its <hostname>. So, in this case, I’m currently kgiii@kgiii-lmde. The ‘kgiii-lmde’ is the hostname. When you open your terminal, in all likelihood it shows you the <user>@<hostname> at the start of your regular prompt.

You can do some neat stuff with the hostname. For instance, and depending on the distro, it’s often local or localhost, you can connect to your LAN devices (without knowing the IP address) by connecting to <hostname>.local. This is handy for using SSH around the house, or even for using FTP or whatever.

If you don’t know your hostname, you can use one of the following commands to figure it out:

Or you can try:

There are other ways to show the hostname, but those two should be enough to get you sorted out. Either of them will happily spit out the hostname. Now that you know your hostname, it’s time to learn how to …

Change Your Hostname:

Like so many other articles on this site, this one requires an open terminal to continue. So, just press CTRL + ALT + T and your default terminal should open.

With your terminal open, enter the following command:

That should permanently change your hostname to the new hostname you chose to use in the command. You can actually change it temporarily, it will not be persistent between reboots, with the hostname command. to do that you’d just sudo hostname <new_hostname> and it’ll change it for the current session only.

To verify that you’ve changed your hostname, run one of the commands listed in the preamble section of this article. (Just type hostname and to verify you know how to change your hostname.)

Anyhow, that’s all there is to it. You really don’t need anything more than that if you want to change your hostname in Linux. Anyone should be able to follow the few directions needed.

Closure:

There you have it, another article. To think, we’re over 200 articles now. This is just one more among many, and this one is easy enough to follow. If you ever wanted to change your hostname, now you know…

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Change Your Hostname In Linux

This article will tell you how to change your hostname in Linux. It’ll give you a couple of options to use. Both methods are pretty easy, and both are approachable by your Linux newbie. Read on for more information!

If you don’t know what your hostname is, or why you have one, you can take a look at this article. Basically, it’s a handy computer name that you use when you’re using things like SSH or FTP. (The first of those three links would be the best page to learn more about your hostname, but it’s basically just a name for your computer.)

Your hostname is probably something you set during the installation process and seldom thought about again. Unless you’re working with your devices remotely, perhaps with the terminal, it’s not really something that you think about all that often. Well, this article is how about you can change your hostname to something else. 

Why would you want to change it?

Well, you could have duplicated it on another device it by mistake. You may have added more devices and need a new device-naming convention. You may have picked something silly and now want to make it more serious. Your device may be moved to a new network where the name isn’t allowed or already belongs to an existing device. There are any number of reasons why you might want to change your hostname. The key point here being that you can change your hostname.

Onto the article!

Change Your Hostname:

This article, like many, requires an open terminal. You can open the terminal with your keyboard – just press CTRL + ALT + T and your default terminal should open. I’ll start with the easiest of the two ways (that I know) to change your hostname.

Method #1:

The first tool we’ll use to change the hostname is the aptly named ‘hostnamectl’ and to use it, you’d use a command like this:

After that, you’ll need to reboot the system for the changes to take effect. Seeing as you’re already in the terminal, you can actually just reboot the system with this command:

This is the very easy way, and it’s the way I’m going to recommend – even if you’re an advanced user. Alas… There’s another way, albeit a bit more messy, to accomplish this.

Method #2

You can edit ‘/etc/hosts’ and ‘/etc/hostname’, changing the hostname manually. This is also handy if you don’t have hostnamectl as an option. Like above, you’ll need to have a terminal open.

Your first command will be editing the hosts file, and we’ll use ‘nano’ for this. Simply enter the following:

There, you’ll see your hostname (which may also be your username, and often is your username). Just delete that and replace it with your desired new hostname.

When you’re done editing, and seeing as we’re using nano, you can save and exit the editor. Just press CTRL + X, then Y, and then ENTER. (It’s seemingly a little complicated, but not too bad.)

Next, you need to edit the hostname file. The command is similar to the one above, just with a different filename. Enter this:

Find the line that begins with ‘127.0.0.1’ and ends with your current hostname. Erase just the hostname and change it to your desired hostname. To make it more clear, here’s a picture:

change the hostname
Just erase the existing hostname and make it your new hostname. Pretty easy, huh?

Once you’re done with that, just like before, you need to save it. Again, you just press CTRL + X, then Y, and then just hit ENTER. That should save your new hosts file and you’re pretty much done changing your username.

There’s one final step. These changes won’t take effect until after you reboot the system. To change your hostname, you will need to reboot the system after changing these files. That’s usually a painless process and you should be able to use the new hostname after the system is rebooted.

Closure:

Well, it’s another article. If I’m paying enough attention (and if you’re curious about milestones), this marks the 100th article posted on this site. This time, the article tells you how to change your hostname. It’s not something you should have to do often, but these are a couple of ways to change it.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

What is my Hostname in Linux?

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…

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.