Are you encountering a "Connection Refused" error when trying to connect to your WSL (Linux) host? Don't worry, we're here to help you troubleshoot and resolve this issue. This guide is designed for entry-level users and will walk you through the steps to identify and fix the problem.
1. Check WSL Status
The first step is to ensure that your WSL (Windows Subsystem for Linux) is running and active. Open a command prompt by pressing Win + R and typing cmd. In the command prompt, type wsl --list and press Enter. If you see a list of installed distributions, it means WSL is running correctly. If not, you may need to enable WSL or install a Linux distribution from the Microsoft Store.
2. Verify SSH Server
If you're trying to connect to your WSL host using SSH, make sure the SSH server is installed and running. In your WSL terminal, run the command sudo service ssh status. If the SSH server is not running, you can start it by running sudo service ssh start. If the SSH server is not installed, you can install it by running sudo apt-get install openssh-server.
3. Check Firewall Settings
Firewall rules can sometimes block incoming connections to your WSL host. Make sure that the necessary ports are open in your firewall settings. By default, SSH uses port 22, so you need to ensure that port 22 is allowed through the firewall. If you're using a third-party firewall software, consult its documentation for instructions on how to open ports.
4. Verify IP Address
Ensure that you are using the correct IP address to connect to your WSL host. In your WSL terminal, run the command ip addr show eth0. Look for the line starting with inet followed by an IP address. This is the IP address you should use to connect to your WSL host. If the IP address is not displayed or it's not the expected address, you may need to check your network configuration.
5. Check Network Connectivity
Make sure that you have a working network connection between your client machine and the WSL host. You can test this by pinging the IP address of your WSL host from your client machine. Open a command prompt on your client machine and run the command ping <WSL_IP_ADDRESS>. Replace <WSL_IP_ADDRESS> with the IP address obtained in the previous step. If the ping is successful and you receive responses, it means your network connection is working fine.
6. Restart WSL
If none of the above steps have resolved the issue, you can try restarting the WSL service. Open a command prompt as an administrator and run the command wsl --shutdown. This will stop all running WSL instances. After that, restart WSL by opening a new command prompt and running any WSL command, such as wsl --list. This will start the WSL service again, and you can check if the connection issue has been resolved.
By following these troubleshooting steps, you should be able to resolve the "Connection Refused" error when trying to connect to your WSL host. If the problem still persists, you may need to seek further assistance from a technical expert or consult the official documentation for your specific Linux distribution.
References
| Reference | Description |
|---|---|
| WSL Documentation | Official documentation for Windows Subsystem for Linux. |
| SSH Academy | Comprehensive guide to SSH and its configuration. |
| Windows Firewall Documentation | Instructions for configuring Windows Firewall inbound port rules. |