Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

How to Change Hostname of the Ubuntu Instance in WSL

July 2, 2024
in A, Blog, WSL
0
ADVERTISEMENT

Table of Contents

Change Hostname of the Ubuntu Instance in WSL

If you are running Ubuntu on Windows WSL (Windows Subsystem for Linux) and wondering how to change hostname permanently then follow all steps mentioned below.

1. Check the instance hostname. Here, DESKTOP-EBL2UQ1 is hostname of Ubuntu running in my Windows 11.

zdXVKTNEcwbZuKC9ZtVlc0qxPwXRwTGFxfkjYjpZhcp8b5ZAdeS5uVL7vyv1

2. Open /etc/wsl.conf or create the same if it does not exist using the nano text editor.

sudo nano /etc/wsl.conf
g05I7ASs5DNz5ALlEXlEjxOmxeqYLqWphD1U3ROOQ2ecVnkPApX91jOWmBdT

3. Add following lines in /etc/wsl.conf:

[network]
hostname = SrcCodes
generateHosts = false
  • hostname = webserver will update the hostname in /etc/hostname.
  • generateHosts = false will prevent WSL from automatic generation of /etc/hosts file.
kzq3St86lLSMcen1aeu5cB6zWTdd01sfFIUdeJzDNefcU4EVdXDOgtgPZB56

4. Save and exit from the nano editor.

Note Tip: To save and close the file in nano editor, press > followed by > and then

5. Shut down the WSL 2 distribution using wsl -t ubuntu and relaunch it then checks hostname.

5Agfl1ZmCSReYnGqSqRvmRVzbqH6WweqcmitDHdmLT83dr3n6tqSaQQhOKjM

Unable to resolve host: Name or service not known

The /etc/hosts file change will be overwritten during re-launch of Ubuntu and we’ll get “unable to resolve host <hostname>: Name or service not known” when trying to refresh the update repositories.

sEuFrADChd44XhhmQO7skbt59byjPRQ2J9zCuct4x6QVvwubicSKevBgFtei

To fix it, let’s edit the /etc/hosts file using the nano editor.

sudo nano /etc/hosts

You will see some entries similar to below:

2415Hx4t1CnaYO9dzop3wIX2KzwL8IO8A7mfnFnhSlYovVv0t6Q1w7VYPDJ0

Find all occurrences of hostname (e.g. “DESKTOP-EBL2UQ1”) and replace with new one (e.g. “webserver”).

BbT5hRx8J2Y5A9R8Hv2cGZHQa0xaGfOr54MkkCT8YaGkq5elatMnduFBKKF7

Save and exit from the nano editor. Then fresh the update repositories to verify it works.

2SpClowTVVKDY4dNrev244LDWNxjg19oHAjaNE1keDr5OaTeoXf3teycQenI
ADVERTISEMENT

Not a reader? Watch this related video tutorial:

5/5 - (1 vote)
Previous Post

How to Export PuTTY Settings or Sessions to Another Computer

Next Post

How to Completely Uninstall the Subsystem for Linux WSL on Windows

Related Posts

Images Hidden Due To Mature Content Settings In CivitAI

August 31, 2024

Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

August 20, 2024

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024

How to Remove The Test Mode Watermark Without Disabling Test Mode

July 28, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory