Setting up Prosody XMPP server on WSL2: Unknown address for existing Windows machines

Abstract: Resolve WSL2 dynamic IP changes preventing Windows clients from connecting to Prosody by configuring port forwarding and binding to 0.0.0.0.

Created: 2026-09-20 by

Configuring Prosody on WSL2 requires resolving the dynamic IP issue inherent to the virtualized network. You must enable port forwarding via .wslconfig and configure Prosody to listen on 0.0.0.0 so Windows clients can connect using a stable hostname rather than a shifting internal address.

Understanding the WSL2 Network Model

WSL2 operates as a lightweight utility VM running inside Hyper-V. By default, it is assigned a private IPv4 address that changes every time the subsystem restarts or your host machine reconnects to the network. This behavior makes direct IP-based connections from Windows clients unreliable because the target address becomes invalid almost immediately after a reboot. To solve this, you cannot rely on querying the current IP address dynamically in your client configurations. Instead, you need a mechanism that maps a consistent local address to the transient WSL2 instance. The standard approach involves configuring Windows to forward traffic from a specific localhost port to the WSL2 internal IP. This process is detailed in our guide on Configuring Port Forwarding with WSL2 and IP Passthrough, which explains how to establish this bridge between the host OS and the guest Linux environment.

Configuring .wslconfig for Port Forwarding

The first step is to instruct Windows to forward incoming connections to your Prosody ports. You do this by creating or editing the .wslconfig file in your Windows user profile directory (e.g., C:\Users\YourName\.wslconfig). This file controls global WSL2 settings. Add the following configuration block to map the standard XMPP ports (5222 for client connections and 5269 for server-to-server) to localhost:
[wsl2]
forwarding=5222:localhost:5222
forwarding=5269:localhost:5269
forwarding=5280:localhost:5280
Note that the syntax uses forwarding, not ipPassthrough, which is an invalid key for this context. After saving the file, you must fully shut down and restart WSL2 for these changes to take effect. Use the command wsl --shutdown from PowerShell or Command Prompt, followed by restarting your distribution. Verify that the ports are listening on localhost within Windows by running netstat -ano | findstr :5222. If the output shows 127.0.0.1:5222 in a LISTENING state, the forwarding rule is active.

Prosody Configuration for External Access

Even with port forwarding enabled, Prosody might still refuse connections if it is only bound to the loopback interface of the WSL2 VM itself. You must explicitly tell Prosody to accept connections from any interface. Edit your main configuration file, typically located at /etc/prosody/prosody.cfg.lua. Look for the interfaces setting. It should be set to listen on all available network interfaces:
interfaces = { "0.0.0.0", "::" }
If this line is missing or commented out, Prosody defaults to binding only to localhost within the WSL2 environment. While port forwarding sends traffic to the WSL2 IP, the application inside may reject it if it isn't listening on the correct network adapter. Changing this to 0.0.0.0 ensures that the XMPP daemon accepts packets arriving from the forwarded localhost port on the Windows host. Additionally, ensure that your virtual host is correctly defined. In the same configuration file, add your domain:
VirtualHost "yourdomain.com"
    ssl = {
        key = "/path/to/key.pem";
        certificate = "/path/to/cert.pem";
    }
    authentication = "internal_hashed"
Replace yourdomain.com with your actual domain or a local testing domain like local.prosody. If you are testing locally without DNS, you will need to handle name resolution separately, which we discuss below.

DNS and Hostname Resolution

Since the IP address is hidden behind the localhost forwarding, Windows clients must resolve your XMPP domain to 127.0.0.1. For local development, you can add an entry to the Windows hosts file located at C:\Windows\System32\drivers\etc\hosts:
127.0.0.1 yourdomain.com
This trick allows any XMPP client on the Windows machine to connect to yourdomain.com and have the traffic automatically routed through the forwarding rules to the WSL2 Prosody instance. This avoids the need for complex DNS server setups during initial configuration.

Firewall and Client Connection

Windows Defender Firewall may block inbound connections even if port forwarding is configured. Ensure that the firewall allows traffic on the forwarded ports. Usually, enabling the "Private Network" profile for WSL-related processes handles this, but you can manually create inbound rules for ports 5222 and 5269 if necessary. Once configured, test the connection using an XMPP client like Gajim or Pidgin. Set the server address to yourdomain.com and the port to 5222. The client should connect successfully because the request hits localhost, passes through the forwarding layer, reaches the WSL2 Prosody instance listening on 0.0.0.0, and is processed normally. For more advanced networking scenarios involving mirrored network modes, refer to WSL2 and Mirrored Network Mode: A Compatibility Overview for Dev Projects, though standard port forwarding is sufficient for most Prosody deployments.

Frequently Asked Questions

Why does my XMPP client fail to connect despite correct credentials?

The failure is usually due to SSL/TLS certificate mismatches or incorrect host resolution. Ensure that the certificate provided to Prosody matches the domain name exactly. Additionally, verify that your Windows hosts file points the domain to 127.0.0.1, as clients cannot resolve the WSL2 dynamic IP directly.

Can I use a static IP instead of port forwarding?

While technically possible by scripting a DHCP reservation, it is highly discouraged. WSL2 IPs change frequently due to its virtualized nature. Port forwarding via .wslconfig is the supported and robust method designed specifically to handle these dynamic changes transparently.

What if I get a connection refused error on port 5222?

Check if Prosody is actually listening on 0.0.0.0 inside WSL2 using ss -tlnp | grep 5222. If it only shows 127.0.0.1, update the interfaces setting in prosody.cfg.lua to include 0.0.0.0 and restart the service. Also confirm that Windows Firewall is not blocking the forwarded traffic.

Does this setup work for server-to-server (S2S) connections?

Yes, but you must also forward port 5269 in your .wslconfig file. Other XMPP servers attempting to connect to your domain will hit the public IP of your Windows machine, which then forwards the traffic to the WSL2 instance on port 5269. Ensure your DNS MX records point to your Windows public IP.

Is it safe to run Prosody on WSL2 for production?

WSL2 is primarily intended for development and testing environments. While it can function, it lacks the stability guarantees and persistent uptime of a native Linux server. For production use, deploy Prosody on a dedicated Linux VPS or container orchestration platform rather than relying on the WSL2 runtime.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More