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).
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 11
- Comments: 15 (4 by maintainers)
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:
– 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:
10.1.1.0/24, which will be an HA group amongst all subnet routers advertising that routefd7a: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/24one would usetailscale debug:Therefore the subnet router should
--advertise-routes=10.1.1.0/24,fd7a:115c:a1e0:b1a:0:7:a01:100/120You 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:
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.
@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=falsesupport with 4via6 routing into a feature request in https://github.com/tailscale/tailscale/issues/4957.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/24as192.168.2.0/24for other machines in192.168.1.0/24, and found a solution sufficient at least for me. Using Ubuntu to serve as a subnet router, and assume192.168.2.0/24is advertised. Firstly, turn on ip forwarding with# echo 1 > /proc/sys/net/ipv4/ip_forward. Then add DNAT rule to create “fake” or “alias” subnet192.168.2.0/24for actual subnet192.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/24Or we can DNAT specific ip address such as192.168.2.100withDNATrule (instead ofNETMAP). Then devices with192.168.1.xxxcan be accessed with192.168.2.xxxaddresses for every other tailscale clients. If we want to use192.168.2.xxxin the Ubuntu machine advertising192.168.1.2, we can addOUTPUTrule (instead ofPREROUTING). 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.