Why can’t ROS 2 find my robots on the LAN when I run it inside WSL2?

WSL2 Hyper-V Firewall (CLI)

WSL2 Hyper-V Firewall – Demo

WSL2 Hyper-V Firewall CLI demonstration GIF

Manage Windows Hyper-V firewall rules from WSL. One command to create/search/delete TCP/UDP/ICMP rules for specific IPs — no GUI, no guesswork.

Script: wsl_ros2_hv_firewall.py (run inside WSL; it calls powershell.exe on Windows)

Why this is useful (ROS / ROS 2)

If your robot is on the LAN and your nodes run in WSL2, Windows’ Hyper-V firewall often blocks:

This tool opens the right paths between WSL ↔ Windows ↔ your robot’s IP(s) so discovery works, topics show up, and connections stop timing out — without disabling the firewall or allowing the whole subnet.

FAQ — Troubleshooting (“it doesn’t work”)

(These reflect common reports: NAT/mirroring differences and Windows/Hyper-V firewall behavior frequently break DDS/multicast discovery.) Stack Overflow

Networking note (required for ROS)

Enable WSL’s mirrored networking so DDS/multicast and inbound traffic reach WSL correctly:

# %UserProfile%\.wslconfig
[wsl2]
networkingMode=mirrored

Then restart WSL:

wsl --shutdown

(These rules target Hyper-V in mirrored mode and play nicely with ROS.)

FAQ — Configuration / How-to

(Mirrored mode can help but has edge cases; Hyper-V-specific firewall rules are the documented way to allow inbound traffic to the WSL VM.) Microsoft Learn

Features

Requirements

Windows PowerShell

Zusätzlich zu WSL kannst du das Skript auch direkt in Windows PowerShell ausführen (ohne WSL):

py -3 wsl_ros2_hv_firewall.py -h
# oder
python wsl_ros2_hv_firewall.py -h

Voraussetzung: Python ist unter Windows installiert/auffindbar. Das Skript ruft die benötigten PowerShell-Cmdlets lokal auf.

FAQ — Commands / Examples

(There are documented PowerShell Get/Set/New-NetFirewallHyperVRule flows and many community example scripts.) Microsoft Learn

Quick start

# Help
python3 wsl_ros2_hv_firewall.py -h

# ROS/ROS2: allow all protocols IN+OUT for a robot IP (scoped to a single host)
python3 wsl_ros2_hv_firewall.py create --ip 192.168.0.213

# ROS1 (tighter): allow TCP IN for ports 11311,8080 only
python3 wsl_ros2_hv_firewall.py create \
  --ip 192.168.0.213 \
  --protocol tcp \
  --direction in \
  --local-ports 11311,8080 \
  --remote-ports 11311,8080

# Search rules (and also write a JSON snapshot)
python3 wsl_ros2_hv_firewall.py --db search

# Delete by exact/wildcard name (dry run first)
python3 wsl_ros2_hv_firewall.py delete --name 'WSL-ROS2-*' --dry-run

# More examples
python3 wsl_ros2_hv_firewall.py examples

FAQ — Troubleshooting / Debugging

(Common debugging steps include using ros2 multicast send/receive, Wireshark on the host interface, and verifying subnet/mirroring.) docs.ros.org

FAQ — Security / Production readiness

(Best practice: scope rules to specific VM/host IPs and ports; use scripted Get-* checks before creating/deleting rules.) Microsoft Learn

Notes


If this helped your ROS setup in WSL, a ⭐️ would be awesome.
Spotted a bug or have an idea? Issues and PRs welcome!

References

  1. raspberry pi - ROS2 communication between WSL and rpi — Stack Overflow
  2. Accessing network applications with WSL — Microsoft Learn
  3. Configure Hyper-V firewall — Microsoft Learn
  4. Installation troubleshooting — ROS 2 Documentation — docs.ros.org
  5. not getting udp multicast working in the new mirrored … — GitHub Discussions
  6. ros2multicast — CLI tool (send/receive) — docs.ros.org
  7. Advanced settings in WSL (.wslconfig) — networkingMode=mirrored — Microsoft Learn
  8. WSL update introducing “Mirrored” networking — Microsoft DevBlogs

© 2025 — WSL2 Hyper-V Firewall (CLI)