I am looking for some iptables rules which can help me to route some traffic from a server :
Client 1 ----|
Client 2 ----| |----------|
Client N ----| ssh, | Server B |
| http, | (NAT) |
| ... |----------|
| |
| |----------| |
-------------| Server A |------------|
|----------| (all traffic initiated
by A should be redirected
to B)
Any client should be able to access some services located on Server A like ssh, http, etc (no special work is needed here).
To answer some requests initiated by a client (like a HTTP request), Server A should fetch some information outside but it should have the IP of the Server B which is a NAT (in reality we have a lot of Server A).
My question is: how to set iptables on Server A to route all outbound traffic initiated by Server A through Server B.
Server A
to the IP address ofServer B
?iptables -t nat -A PREROUTING -i eth0 -j DNAT --to-destination x.x.x.x
butwget -qO- ifconfig.me/ip
always return the IP of Server A and not x.x.x.x