tailscale: NAT (DNAT) conflicting subnets in advertise-routes

Some users report that they have the same subnet (say, 192.168.1.0/24) in multiple locations, containing different devices. If they advertise these unrelated subnets into the same tailscale network, there’s no way to differentiate between them.

Obviously the “right” solution is to change those subnet numbers to all be non-overlapping, but that can be intrusive and hard to justify for legacy reasons.

As a workaround, we could have tailscale NAT the traffic to/from those subnets on the way through. The syntax could be something like: --advertise-routes=192.168.1.0/24=10.11.0.0/16,192.168.2.0/24=10.12.1.0/24 which means map the 192.168.1.0/24 addresses into the 10.11.0.0 subnet, and advertise that to peers as if it were 10.11.0.0/16 (and similar with the second subnet).

Front logo Front conversations

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 11
  • Comments: 15 (4 by maintainers)

Most upvoted comments

Quick poll: would IPv6 subnets help any of the people in this thread? Maybe give this comment a thumbs up/down for yes/no. Thanks! ᐧ

On Tue, Oct 20, 2020 at 2:26 PM CMor1184 notifications@github.com wrote:

This is exactly the problem I currently have. I have several industrial machines with the same subnet in different locations and want to connect them with Tailscale. Unfortunately I have not been able to do this yet. Therefore I would like to vote very strongly for a solution!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tailscale/tailscale/issues/826#issuecomment-713051904, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAFA4DEFT2JDL4GBZ5JLRLSLXI4HANCNFSM4ST5EAIQ .

– Avery Pennarun // CEO @ Tailscale

We have the initial step of a possible solution in the 1.24.x release. A subnet router can advertise both:

  • the IPv4 route like 10.1.1.0/24, which will be an HA group amongst all subnet routers advertising that route
  • a unique IPv6 address for itself specifically, of the form fd7a:115c:a1e0:b1a:0:X:a01:100, where X is an ID 1-255 which needs to be unique for each subnet router and a01:100 is the IPv6 display representation of 10.1.1.0.

Nodes on the tailnet which connect to fd7a:115c:a1e0:b1a:0:7:a01:106 (ID = 7) will be directed to the subnet router whose ID is 7, which will then rewrite the packet to be an IPv4 packet for destination 10.1.1.6. You can therefore uniquely address each overlapping 10.1.1.0/24 subnet by using a different ID in the IPv6 address advertised by each subnet router.

There are several utilities to help administer this.

To generate the IPv6 route for ID=7 and 10.1.1.0/24 one would use tailscale debug:

$ tailscale debug via 7 10.1.1.0/24
fd7a:115c:a1e0:b1a:0:7:a01:100/120

Therefore the subnet router should --advertise-routes=10.1.1.0/24,fd7a:115c:a1e0:b1a:0:7:a01:100/120 You don’t have to advertise 10.1.1.0/24 if it is never going to be useful to have the HA IPv4 subnet route.

MagicDNS names are also created, for example to reach 10.1.1.6 using ID=7:

$ ping 10.1.1.6.via-7

Finally, the inception variation of the feature: if you create multiple subnet routers advertising as ID=7 (for example), the coordination server will treat them as a High Availability group and choose one to be active. Please use this sparingly: if we have to implement a double indirect via-via feature in the future I’m going to be very cross with all of you.


This feature should be considered experimental, we’re looking for feedback on whether it solves the needed cases and how well it works.

I also wanted to advertise 192.168.1.0/24 as 192.168.2.0/24 for other machines in 192.168.1.0/24, and found a solution sufficient at least for me. Using Ubuntu to serve as a subnet router, and assume 192.168.2.0/24 is advertised. Firstly, turn on ip forwarding with # echo 1 > /proc/sys/net/ipv4/ip_forward. Then add DNAT rule to create “fake” or “alias” subnet 192.168.2.0/24 for actual subnet 192.168.1.0/24. sudo iptables -t nat -A PREROUTING -i tailscale0 -d 192.168.2.0/24 -j NETMAP --to 192.168.1.0/24 Or we can DNAT specific ip address such as 192.168.2.100 with DNAT rule (instead of NETMAP). Then devices with 192.168.1.xxx can be accessed with 192.168.2.xxx addresses for every other tailscale clients. If we want to use 192.168.2.xxx in the Ubuntu machine advertising 192.168.1.2, we can add OUTPUT rule (instead of PREROUTING). relates to: #1227 #1344 #6231

@ge9 Thank you so much this is what i was searching for!

To summarise i got two nets both with 192.168.178.x I want to access the second using subnet routing now ips overlap for example https://192.168.178.1/

Solution

Enable IP forwarding

echo 1 > /proc/sys/net/ipv4/ip_forward

change dnat rule

iptables -t nat -A PREROUTING -i tailscale0 -d 192.168.179.0/24 -j NETMAP --to 192.168.178.0/24

advertise route using tailscale

tailscale up --advertise-routes=192.168.179.0/24

enable advertised route in tailscale admin console

ping and check for connection

ping 192.168.179.1 ping 192.168.178.1 both should reach different hosts

Turned --snat-subnet-routes=false support with 4via6 routing into a feature request in https://github.com/tailscale/tailscale/issues/4957.

Just wanted to chime in and say that I’ve been experimenting with this and this feature is really useful so I hope it remains in Tailscale in some shape or form.

I expect it to remain in the product, it solves a significant problem. We published documentation https://tailscale.com/kb/1201/4via6-subnets/. It is considered an Alpha feature because it needs more coverage in the admin panel of what it is doing before we’d make it Beta or Generally Available.

Being able to map/nat the overlapping subnet when advertising them (or even better via admin console when enabling) would be very handy as sometimes changing them is not an option (eg aws vpc subnet cannot be changed, you need to recreate)

I also wanted to advertise 192.168.1.0/24 as 192.168.2.0/24 for other machines in 192.168.1.0/24, and found a solution sufficient at least for me. Using Ubuntu to serve as a subnet router, and assume 192.168.2.0/24 is advertised. Firstly, turn on ip forwarding with # echo 1 > /proc/sys/net/ipv4/ip_forward. Then add DNAT rule to create “fake” or “alias” subnet 192.168.2.0/24 for actual subnet 192.168.1.0/24. sudo iptables -t nat -A PREROUTING -i tailscale0 -d 192.168.2.0/24 -j NETMAP --to 192.168.1.0/24 Or we can DNAT specific ip address such as 192.168.2.100 with DNAT rule (instead of NETMAP). Then devices with 192.168.1.xxx can be accessed with 192.168.2.xxx addresses for every other tailscale clients. If we want to use 192.168.2.xxx in the Ubuntu machine advertising 192.168.1.2, we can add OUTPUT rule (instead of PREROUTING). relates to: https://github.com/tailscale/tailscale/issues/1227 https://github.com/tailscale/tailscale/issues/1344 https://github.com/tailscale/tailscale/issues/6231

@DentonGentry We’ve been using the site relative IPv4 to IPv6 feature for 2 weeks now. Zero issues. Our tailnet is now connected to 3 networks that use the same IP ranges. This solves our needed case. We weren’t aware of the automatic Magic DNS names, we’ll give them a try as well.

Thought about running into this issue as I begin to field test Tailscale, I envision some way to select with exposed subnet route you want to access, and a way to make all exposed routes unable to speak to each other unless otherwise permitted.