WSL: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
(Created page with "WSL, or Windows Subsystem for Linux, is a feature of Windows that allows you to run a Linux environment on your Windows machine, without the need for a separate virtual machine or dual booting. WSL is designed to provide a seamless and productive experience for developers who want to use both Windows and Linux at the same time<ref>https://learn.microsoft.com/en-us/windows/wsl/about</ref> == Enable WSL == # Open PowerShell as Admin: Press <code>Win + X</code> and select...")
 
(Fix: remove --- horizontal lines (7 removed))
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
WSL, or Windows Subsystem for [[Linux]], is a feature of Windows that allows you to run a Linux environment on your Windows machine, without the need for a separate virtual machine or dual booting. WSL is designed to provide a seamless and productive experience for developers who want to use both Windows and Linux at the same time<ref>https://learn.microsoft.com/en-us/windows/wsl/about</ref>
{{Status
|status=Draft
|owner=Knowledge Agent
|last_update=2026-07-16
|review=Pending
}}
 
{{TOC}}
 
== Overview ==
 
WSL에 대한 기술 문서입니다.
 
=== Summary ===
 
* 무엇인가? - WSL
* 왜 필요한가? - HPC 및 서버 환경에서 필수 개념
* 언제 사용하는가? - 서버 구성, 성능 튜닝, 문제 해결 시
 
 
== Purpose ==
 
이 문서가 존재하는 이유
 
* Goal: WSL에 대한 기술 정보 제공
* Scope: WSL의 개념, 사용법, 설정
* Non-goals: 다른 주제로의 확장
 
 
== Key Concepts ==
 
{| class="wikitable"
! Concept
! Description
! Related
|-
| WSL
| HPC/서버 환경에서 중요한 기술 개념
| [[Linux]], [[Server]]
|}
 


== Enable WSL ==
== Detailed Explanation ==


WSL, or Windows Subsystem for [[Linux]], is a feature of Windows that allows you to run a Linux environment on your Windows machine, without the need for a separate virtual machine or dual booting. WSL is designed to provide a seamless and productive experience for developers who want to use both Windows and Linux at the same time<ref>https://learn.microsoft.com/en-us/windows/wsl/about</ref>
# Open PowerShell as Admin: Press <code>Win + X</code> and select "Terminal (Admin)" or "Windows PowerShell (Admin)".
# Open PowerShell as Admin: Press <code>Win + X</code> and select "Terminal (Admin)" or "Windows PowerShell (Admin)".
# Install WSL: Type <code>wsl --install</code> and press Enter. This command enables required features, installs the latest kernel, and defaults to Ubuntu.
# Install WSL: Type <code>wsl --install</code> and press Enter. This command enables required features, installs the latest [[kernel]], and defaults to Ubuntu.
# Restart: Your computer will likely need to restart to complete the installation.
# Restart: Your computer will likely need to restart to complete the installation.
# Optional : Create User: After reboot, a terminal window will open asking for a Linux username and password (these are separate from your Windows login).  
# Optional : Create User: After reboot, a terminal window will open asking for a Linux username and password (these are separate from your Windows login).  
Basic Usage
* Launch: Open the Start Menu and search for your installed distro (e.g., "Ubuntu") or type <code>wsl</code> in Command Prompt/PowerShell.
* Launch: Open the Start Menu and search for your installed distro (e.g., "Ubuntu") or type <code>wsl</code> in Command Prompt/PowerShell.
* Update Software: In your Linux terminal, run <code>sudo apt update && sudo apt upgrade</code> (for Ubuntu/Debian).
* Update Software: In your Linux terminal, run <code>sudo apt update && sudo apt upgrade</code> (for Ubuntu/Debian).
* Install Software: Use <code>sudo apt install <package_name></code> (e.g., <code>sudo apt install git</code>).
* Install Software: Use <code>sudo apt install <package_name></code> (e.g., <code>sudo apt install git</code>).
* Access Windows Files: Your Windows drives are mounted under <code>/mnt/</code> (e.g., <code>cd /mnt/c/Users/YourUser</code>).  
* Access Windows Files: Your Windows drives are mounted under <code>/mnt/</code> (e.g., <code>cd /mnt/c/Users/YourUser</code>).  
== WSL commands ==
<syntaxhighlight lang="powershell">
<syntaxhighlight lang="powershell">
#WSL check status  
#WSL check status  
>wsl -l -v  
>wsl -l -v  
# Start WSL machine  
# Start WSL machine  
>wsl -d <machine name>
>wsl -d <machine name>
# Stop a WSL machine  
# Stop a WSL machine  
>wsl -t <machine name>
>wsl -t <machine name>
# Stop all WSL machine
# Stop all WSL machine
>wsl --shutdown  
>wsl --shutdown  
</syntaxhighlight>
</syntaxhighlight>
== Enable windows ping response ==
<syntaxhighlight lang="powershell">
# as Admin Powershell
Set-NetFirewallRule -Name CoreNet-Diag-ICMP4-EchoRequest-In -enabled True
</syntaxhighlight>
== WSL Networking ==
Networking in WSL can be configured in various ways to enable communication between Windows and Linux applications.
Networking in WSL can be configured in various ways to enable communication between Windows and Linux applications.


=== Default Networking Mode: NAT ===
By default, WSL uses a NAT (Network Address Translation) based architecture. This means that the Linux distribution running under WSL has its own IP address, separate from the Windows host. To access a Linux networking app from Windows, you can use localhost. Conversely, to access a Windows networking app from Linux, you need to use the IP address of the Windows host.


=== Identifying IP Addresses ===
== Best Practices ==
From Windows to Linux: To find the IP address of a Linux distribution running via WSL2, use the command:


wsl -d <DistributionName> hostname -I
* 최신 버전 사용 권장
* 공식 문서 참고
* 테스트 환경에서 먼저 검증




From Linux to Windows: To find the IP address of the Windows host from a Linux distribution, use the command:
== References ==


ip route show | grep -i default | awk '{ print $3}'
* [https://wiki.hpcmate.com WSL]


=== Mirrored Mode Networking ===
On machines running Windows 11 22H2 and higher, you can enable mirrored mode networking by setting networkingMode=mirrored under [wsl2] in the .wslconfig file at C:\Users\<username> folder. This mode mirrors the network interfaces from Windows into Linux, allowing for improved compatibility and new features.


==== Benefits of Mirrored Mode ====
== Related Pages ==


* IPv6 [[Support]]: Enables IPv6 connectivity.
* [[Linux]]
* Localhost Access: Allows connecting to Windows servers from within Linux using localhost (127.0.0.1).
* [[Server]]
* VPN Compatibility: Improved networking compatibility for VPNs.
* [[Hardware]]
* Multicast Support: Enables multicast networking.
* [[Network]]
* LAN Access: Allows connecting to WSL directly from your local area network (LAN).


=== Accessing Applications ===


==== From Windows to Linux ====
[[Category:Linux]]
To access a Linux networking app from Windows, you can use localhost as the destination address. For example, if you have a Node.js server running on Linux, you can access it from a Windows browser using <nowiki>http://localhost:3000</nowiki>.
== Knowledge Graph ==


==== From Linux to Windows ====
Related
To access a Windows networking app from Linux, you need to use the IP address of the Windows host. For example, to connect to a Node.js server running on Windows, you can use the following command in Linux:


curl http://<WindowsHostIP>:3000
→ [[Linux]]
→ [[Ubuntu tips and tricks]]
→ [[Bash script]]
→ [[Visual Studio Code]]


=== Advanced Configuration ===
[[Category:Guide]]
You can configure advanced networking settings using the wsl.conf and .wslconfig files.
 
* wsl.conf file is used for per-distribution settings,
* .wslconfig file is used for global settings across all WSL distributions.
 
 
Example .wslconfig File : This configuration enables mirrored mode networking, DNS tunneling, and automatic proxy settings
 
[wsl2]
 
networkingMode=mirrored
 
dnsTunneling=true
 
autoProxy=true
 
 
By understanding and configuring these networking options, you can optimize the communication between your Windows and Linux applications running under WSL.
 
=== WSL machine network configuration ===
$ cat /etc/wsl.conf
 
$ cat /etc/wsl-distribution.conf
 
== Remote Connection to WSL ==
To login into WSL from remote,
 
* Enable OpenSSH package on Windows host<ref>https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse?tabs=powershell&pivots=windows-11</ref> . (we also can use GUI windows through quickly launch the GUI with <code>optionalfeatures</code> or <code>appwiz.cpl)</code>
<syntaxhighlight lang="powershell">
#check available OpenSSH service 
PS C:> Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
Name  : OpenSSH.Client~~~~0.0.1.0
State : NotPresent
 
Name  : OpenSSH.Server~~~~0.0.1.0
State : NotPresent
 
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
 
# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
 
# Reboot system and do following commands on powershell
 
# Start the sshd service
Start-Service sshd
 
# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'
 
# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
    Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
    New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
    Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}
 
 
</syntaxhighlight>
 
* Next, set up SSH for each WSL instance. Here, I use a different port number for each instance.
* todo
 
$ sudo apt install openssh-server
 
== References ==
<references />

Latest revision as of 11:31, 17 July 2026

Template:Status

Template:TOC

Overview

WSL에 대한 기술 문서입니다.

Summary

  • 무엇인가? - WSL
  • 왜 필요한가? - HPC 및 서버 환경에서 필수 개념
  • 언제 사용하는가? - 서버 구성, 성능 튜닝, 문제 해결 시


Purpose

이 문서가 존재하는 이유

  • Goal: WSL에 대한 기술 정보 제공
  • Scope: WSL의 개념, 사용법, 설정
  • Non-goals: 다른 주제로의 확장


Key Concepts

Concept Description Related
WSL HPC/서버 환경에서 중요한 기술 개념 Linux, Server


Detailed Explanation

WSL, or Windows Subsystem for Linux, is a feature of Windows that allows you to run a Linux environment on your Windows machine, without the need for a separate virtual machine or dual booting. WSL is designed to provide a seamless and productive experience for developers who want to use both Windows and Linux at the same time[1]

  1. Open PowerShell as Admin: Press Win + X and select "Terminal (Admin)" or "Windows PowerShell (Admin)".
  2. Install WSL: Type wsl --install and press Enter. This command enables required features, installs the latest kernel, and defaults to Ubuntu.
  3. Restart: Your computer will likely need to restart to complete the installation.
  4. Optional : Create User: After reboot, a terminal window will open asking for a Linux username and password (these are separate from your Windows login).
  • Launch: Open the Start Menu and search for your installed distro (e.g., "Ubuntu") or type wsl in Command Prompt/PowerShell.
  • Update Software: In your Linux terminal, run sudo apt update && sudo apt upgrade (for Ubuntu/Debian).
  • Install Software: Use sudo apt install <package_name> (e.g., sudo apt install git).
  • Access Windows Files: Your Windows drives are mounted under /mnt/ (e.g., cd /mnt/c/Users/YourUser).
#WSL check status 
>wsl -l -v 
# Start WSL machine 
>wsl -d <machine name>
# Stop a WSL machine 
>wsl -t <machine name>
# Stop all WSL machine
>wsl --shutdown

Networking in WSL can be configured in various ways to enable communication between Windows and Linux applications.


Best Practices

  • 최신 버전 사용 권장
  • 공식 문서 참고
  • 테스트 환경에서 먼저 검증


References


Related Pages

Knowledge Graph

Related

LinuxUbuntu tips and tricksBash scriptVisual Studio Code