-1

How to route traffic to a destination to another destination and receive response using iptables

I have two vps on cloud. Lets say VPS-A and VPS-B.

If a request to 8.8.8.8 generated from VPN-A, I want to route that request to VPS-B. Then VPS-B should accept that request and return the response.

what are the iptable rules to achieve this?

2
  • routing is done with ip route commands, not iptables. Iptables is a manages the firewall. What you may be looking for is some kind of vpn or proxy.
    – Zoredache
    Aug 11, 2014 at 20:06
  • You are right, VPS-B is installed with openswan and vpn tunnel is up and running. VPS-A is a client machine of VPS-B. Since both were remote machines, I cant set the gateway to VPS-B with ip route command. So I'm looking for some iptable rules to forward some specific request to VPS-B. Aug 12, 2014 at 2:37

1 Answer 1

0

You said you need only iptables part. OK. Here it is (quite simple). This must be on VPS-B:

iptables -I FORWARD -s 8.8.8.8 -j ACCEPT
iptables -I FORWARD -d 8.8.8.8 -j ACCEPT

These two rules will accept all traffic from and to 8.8.8.8 to pass trough VPS-B. Routing is for you.

2
  • what about iptable rules in VPS-A to forward a specific request to VPS-B ? Aug 12, 2014 at 2:27
  • You did not say anything about specific request, you wanted only acceptance from VPS_B. The rest is routing.
    – LHristov
    Aug 12, 2014 at 4:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .