toxuin / mdns-tunneller

Tunnels two (or more) mDNS domains together
Other
117 stars 9 forks source link

How can one specify the interface used for the client/server? #10

Closed seidnerj closed 2 years ago

seidnerj commented 2 years ago

I want to run both on a single machine which has a "leg" in two networks. For each network there is a separate interface, e.g. en0 for the local network and utun5 for the remote network (in this case via a VPN).

Currently there isn't a way to specify the interface for either the client or the server so running both on the same machine uses the same interface and is thus useless.

I couldn't find how one can specify in Primus the interface that should be used for a socket.

Any help would be appreciated.

Thanks in advance.

toxuin commented 2 years ago

This sounds like a good use case when usage of something like avahi-reflector would be sufficient - no tunnelling necessary.

Unless I'm missing something?

seidnerj commented 2 years ago

Can't run Avahi on the target machine unfortunately because I already have a different mDNS server running there (bundled with some piece of software that's installed) and running multiple mDNS servers is probably not a good idea.

toxuin commented 2 years ago

You can try using two separate config files for a client and server, and specify only one interface for each within mdnsInterfaces section config. Weird use cases like that is where this project shines šŸ˜„ Let me know how it goes!

seidnerj commented 2 years ago

Will give it a go, thanks!

seidnerj commented 2 years ago

After experimentation and some thinking I realize that no solution would really work for my scenario (mdns-tunnler, mdns-repeater, avahi reflection or others).

This lies in the fact that while mDNS packets can by relayed between any two (or more) interfaces and resent appropriately by any of the aforementioned methods, it does not work for most virtual interfaces used by VPNs (OpenVPN, WireGuard, possibly more).

Essentially, it seems Multicast and Broadcast is not usually supported by such interfaces, and while such packets can be sent to a VPN's interface, it would not be relayed by the VPN server to other VPN clients, even those on the same subnet.

Really the only way to achieve this is by creating a bridge interface (e.g. TAP on OpenVPN), that way the VPN clients are indeed in the same network as the LAN and all Broadcast and Multicast packets are delivered correctly. As far as I understand, in such case no repeater-like solution would be needed anyways.

Unfortunately, TAP is not supported by iOS or Mac OS X, so I think in my specific case there really isn't any way to achieve visibility of services available on local LAN via mDNS for VPN clients connecting from an external network.

These solutions could work great for other cases, say if there are two separate networks connected by a VPN between them, since the packet to be relayed could be sent over the VPN and then relayed by a non-virtual interface to the rest of the remote network.

Alas, if we're not talking about an actual network but rather a bunch of iOS/Mac VPN clients sharing a subnet, this seems like it is not possible with the current implementations available.

Too bad!

toxuin commented 2 years ago

That aligns pretty well with what I have seen so far too. This project is for tunnelling networks, not individual devices.

However, there is one saving grace - I am not sure if that would apply to your particular use case or not, but you can set up the tunneller client on the other side of the VPN and essentially bridge two end-networks together (instead of bridging the VPN network itself to your source network). This will not do much if your goal is to pretend you're at home while you're on LTE, but can be useful when you have two houses and wish to connect their mDNS "domains" together, for example.

If you're trying to control a homekit while being away from home - the only solution I've found so far is to get a used AppleTV which will be acting as your homekit proxy through apple's own network.

seidnerj commented 2 years ago

Hehe, unfortunately the use case you mentioned is exactly what Iā€™m going for - have an iOS device behave as if its in the actual LAN while on a non-WiFi connection and connected to the LAN via a VPN.

Homekit is not the issue for me, I have multiple hubs, Apple TVs, Homepod Minis and more so I can control everything over the Internet.

Unfortunately, there are other services that are advertised on my local network that I want to be able to use while connected from an iOS device using a non-WiFi connection.

Iā€™ve been pondering the option to take the mDNS packet and send it using Unicast to all VPN clients, some sort of Multicast to Unicast conversion. Those packets should be forwarded properly by the virtual interfaces used by VPNs but Iā€™m not sure they would be ā€œcollectedā€ and interpreted properly by the various mDNS clients that reside on the VPN clients. It really depends on what is the inclusion logic used in the mDNS clients to ā€œbuildā€ the map of all the services available.

I might try to test this manually and see if I can propagate a single service via this method. If it works, it should be easy to adjust your existing code to implement this method.