How to Change Your Hostname on WSL Ubuntu in Less Than 2 Minutes

How to change your hostname on wsl ubuntu

  • Note down your hostname
  • Open /etc/wsl.conf or create the same if it does not exist ($vi wsl.conf)
  • Add the following lines in /etc/wsl.conf

[network]
hostname = yourHostname
generateHosts = false

  • Open /etc/hosts and update
Find all occurences of hostname (e.g. "DESKTOP-ABC222") and replace with the new one (e.g. "yourHostname").

  • Close Ubuntu and re-launch
You could open Windows Terminal or Windows PowerShell run wsl --shutdown to shut down the WSL 2 VM and relaunch it.

check it with $echo "$HOSTNAME"




if you need some help with the UNIX commands, please refer to this page https://aufullstackde.blogspot.com/2023/05/basic-unix-commands.html

Enjoy!

No comments:

Post a Comment

Featured Posts

SnowPro Badges and Certificates

SnowPro Badges and Certificates Online Verification https://achieve.snowflake.com/profile/richardhou888/wallet

Popular Posts Recommended