I have following networking setup:
Gateway:
Internet <-- eth0 : a.b.c.d (static address)
Clients <-- eth1 : DHCP at server at 172.16.0.1, leasing 172.16.0.0/24
Client:
Gateway <-- eth0: 172.16.0.0/24
Clients can reach internet and forwarding is working. I want to create some kind of "virtual" address, which clients can access via gateway, but that address would be in fact some machine on the Internet.
So, when they connect to 172.32.1.1
they in fact connect to google and so on. I tried it with NAT:
TARGET=$(dig -q google.com)
VIRTUAL=172.32.1.1
iptables -t nat -A PREROUTING -d "$VIRTUAL" -j DNAT --to "$TARGET"
iptables -t nat -A POSTROUTING -s "$TARGET" -j SNAT --to "$VIRTUAL"
that somehow works, however when I ping it from gateway I get
From 20.249.x.y icmp_seq=1 Destination Net Unreachable
(where 20.249.x.y is my Gateway's gateway), and when I traceroute to that virtual IP from the client, I get this:
traceroute to 172.32.1.1 (172.32.1.1), 30 hops max, 38 byte packets
1 172.32.1.1 (172.32.1.1) 31.886 ms 31.638 ms 34.029 ms
2 172.32.1.1 (172.32.1.1) 39.660 ms 40.489 ms 39.153 ms
3 172.32.1.1 (172.32.1.1) 41.879 ms 40.367 ms 40.436 ms
4 172.32.1.1 (172.32.1.1) 47.375 ms 48.200 ms 48.878 ms
5 172.32.1.1 (172.32.1.1) 47.801 ms 47.280 ms 47.405 ms
That looks super weird to me. Is there a way to fix these issues? I was trying to use ip tunnel
, but it looks like it needs different end setting up as well, which I obviously cannot do.
iptables config on server contains these two rules and -A FORWARD -i eth1 -j ACCEPT
only.
ping
might not work on internet hosts, when targeting google.com doeswget
work ? if yes you are done.