So today while installing Ubuntu 20.04 on my laptop I accidentally gave it the hostname of my desktop and then changed it.

A few hours later I was losing my sanity because SSHing into my desktop PC by providing its hostname resulted in being connected to my current machine.

Long story short, changing hostname in GUI has no effect on /etc/hosts, where the initial hostname is set to

Learned my lesson here, but I still don't understand why this problem even exists. Is there a reason behind it? Why not just change it, assuming it matches the previous hostname?

Upd: Just realized that trying to connect using hostname was itself a stupid idea since there is no way it could have been resolved. Just assumed it worked after messing with Ubuntu under WSL. Still, the question stands.


Sometimes you may need to restart in order for any change to take effect. Also, I do not recommend connecting to machines using their hostname as it can be unreliable and a bit weird sometimes. I recommend just using the IP address instead.

| improve this answer | |
  • You "do not recommend connecting to machines"? – Organic Marble Jul 16 at 21:58
  • My mistake, I meant to say "do not recommend connecting to machines using hostnames". I will edit it now. – Dead Void Jul 16 at 22:01
  • I'm pretty sure I rebooted several times, that's just how it works. I came across a few similar topics but never found an explanation as to why it works this way. – cotneit Jul 16 at 22:27
  • Not 100% sure then, it usually works for me. – Dead Void Jul 16 at 22:28
  • As for using hostname in the first place, yeah, you have a point here. I guess I just assumed it worked, but now realized that I was always using IP instead. – cotneit Jul 16 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.