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 127.0.1.1.
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.