title: Reroute mDNS query from WSL subnet to windows host subnet
body: <p>Heya fellow coders/developers/networkers/Devops/...</p>
  
  <p>I have an issue with an <code>mDNS</code>/<code>DNS-SD</code> setup in the context of WSL2 (Windows 10 2004 version)</p>
  
  <p>I have a pretty simple setup at home with a main server and a Raspberry Pi, and I would like to activate DNS service discovery, thus allowing me to have a simple way to do automatic discovery of my server on my Raspberry PI.</p>
  
  <p>Using a simple library like <a href="https://www.npmjs.com/package/dnssd" rel="noreferrer">dnssd</a>, or even broadcasting the right data myself, I manage to make it work easily when not using WSL2.
  However I have a requirement to make it work on WSL2 and this is where things get complicated.</p>
  
  <p>As WSL2 is running on its own subnet, the broadcasting does not work anymore. Using mDNS on a subnet only works in this subnet.
  However Windows already reroute some of the broadcast traffic between the host and WSL.</p>
  
  <p>This is testable easily : doing a simple <code>Ping</code> from my server to the Avahi address of the Pi which relies on mDNS works.</p>
  
  <p><a href="https://i.stack.imgur.com/quQNB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/quQNB.png" alt="enter image description here"></a></p>
  
  <p>On the left side of the screen you can see traffic captured by Wireshark on the host network interface and on the right side, you can see the traffic captured by Wireshark on the WSL network interface.
  The first 3 lines are a simple ping : it is executed in the context of WSL, but the IP address that appears here - <code>172.28.192.1</code>- is not the IP address of the WSL client, it is the IP address of the internal DNS server of WSL. It is perfectly rerouted on the host as you can see on the right, with the IP address of the windows host: <code>192.168.0.39</code></p>
  
  <p>However, the second query, which is executed by a script, has the WSL source IP (<code>172.28.204.42</code>) and this one is not rerouted on the host.</p>
  
  <p>My network knowledge is very limited and I do not understand how this work, and how I could make WSL route my own mDNS queries on the host. A wild guess would be that it has something to do with iptables, but that is as far as I go.</p>
  
  <p>If anyone has a clue on why it works on the DNS server source address and not when I perform it myself it would help me a lot !</p>
  
  <p>Edit 1 : WSL Route table 
  <a href="https://i.stack.imgur.com/KNyKJ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/KNyKJ.png" alt="enter image description here"></a></p>