LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   using iptables dnat for redirection (https://www.linuxquestions.org/questions/linux-networking-3/using-iptables-dnat-for-redirection-838781/)

Verminoz 10-18-2010 05:46 AM

using iptables dnat for redirection
 
Hello,
I have been trying to achieve something through iptables but something is going wrong. I want connection/packets arriving to a specific computer (let's call it "server") from another specific computer ("client") inside the same network to be automatically redirected to a remote computer in the internet and vice-versa. I tried doing that using iptables with these commands on the "server" PC:

Code:

iptables -t nat -A PREROUTING --source 'client-ip' -j DNAT --to-destination 'remote-pc-ip'
iptables -t nat -A PREROUTING --source 'remote-pc-ip' -j DNAT --to-destination 'client-ip'

but doesn't seem to work at all. To make it more clear I pretty much want the "server" computer to act similar to a proxy.

Any ideas and/or suggestion would be greatly appreciated. Thank you in advance!

Nick

Verminoz 10-18-2010 11:19 AM

Small update, I tried this:

Code:

echo 1 > /proc/sys/net/ipv4/ip_forward
on the server computer and now it seems like something is happening but still there are problems. Apparently when I attempt a connection to the remote computer from the client via the server, the client and the remote pc don't actually exchange data and the connection drops. But it seems there's some kind of interaction because the remote application that is listening for connection stops listening (like there was a connection and it was dropped for some reason).

ndarkduck 10-18-2010 02:35 PM

Code:

iptables -t nat -A PREROUTING --source 'client-ip' -j DNAT --to-destination 'remote-pc-ip'
iptables -t nat -A PREROUTING --source 'remote-pc-ip' -j DNAT --to-destination 'client-ip'

Code:

iptables -t filter -I FORWARD -s 'client-ip' -j ACCEPT
iptables -t filter -I FORWARD -d 'client-ip' -j ACCEPT

Code:

echo 1 > /proc/sys/net/ipv4/ip_forward


All times are GMT -5. The time now is 08:48 PM.