I'm trying to setup load balancer via iptables that will forward new connection to the closest (geographical) node. I've seen examples of blocking traffic by country and was able to setup traditional load balancer that distributes connecting users between few nodes like that:
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport PORTNUM -m state --state NEW -m statistic --mode nth --every 4 --packet 1 -j DNAT --to-destination x.x.x.x:PORTNUM
what I would want to do is to geocode user's location and choose closest server to them to reduce latency. What's gonna be the right way to do that?
I know, I can always write little proxy that'll connect to the right server and act as a real proxy, but I'd really like to make that happen on iptables level.
if that makes any sense, I'm targeting Ubuntu 16.04
I did see http://ipset.netfilter.org/iptables-extensions.man.html but didn't find answer to this question...any help or ideas would be appreciated!