1

Is there a way to have a different hostname on WSL than the actual Windows PC name?

Is there a general way of doing this or is it specific to each distro (Ubuntu vs Debian for example)?

Note : A similar question has been answered here but the answers are either specific to Ubuntu, or just about changing the Windows PC name. I'm more interested in changing the WSL hostname without changing the Windows PC name

I tried

  • hostname [newname] command, added to .bashrc (requires root)
  • tried hostnamectl (fails)
  • tried adding hostname = [hostname] in /etc/wsl.conf (doesn't work on Debian)
madacoda
  • 363
  • 4
  • 11

1 Answers1

0

In general, the way to change the hostname in most if not all linux distributions (including Ubuntu and Debian) is by modifying the /etc/hosts/ and /etc/hostname files.

Find wherever your current name is mentioned and replace it with your desired one.

Note that those also require root privileges (run with sudo).

liakoyras
  • 1,101
  • 12
  • 27