LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Iptables Port forwarding (https://www.linuxquestions.org/questions/linux-networking-3/iptables-port-forwarding-871391/)

pnmanojshenoy 03-28-2011 02:26 AM

Iptables Port forwarding
 
Hello,

I have set a rule in Iptables to do port forwarding to another Ip in

/sbin/iptables -t nat -A PREROUTING -p tcp -i eth+ -d 192.168.2.10 --dport 2200 -j DNAT --to 192.168.70.101:2200
/sbin/iptables -A FORWARD -p tcp -i eth1 -d 192.168.70.101 --dport 2200 -j ACCEPT

The redirect rule is working fine from other PC's but I am not able to do the same from the same machine in which I have configured the IPtables rule ie:

telnet localhost 2200 not working and also telnet 192.168.2.10 2200 not working from the machine whereas it redirection is working from from other PC's

manyrootsofallevil 03-28-2011 03:08 AM

Quote:

Originally Posted by pnmanojshenoy (Post 4305882)
Hello,

I have set a rule in Iptables to do port forwarding to another Ip in

/sbin/iptables -t nat -A PREROUTING -p tcp -i eth+ -d 192.168.2.10 --dport 2200 -j DNAT --to 192.168.70.101:2200
/sbin/iptables -A FORWARD -p tcp -i eth1 -d 192.168.70.101 --dport 2200 -j ACCEPT

The redirect rule is working fine from other PC's but I am not able to do the same from the same machine in which I have configured the IPtables rule ie:

telnet localhost 2200 not working and also telnet 192.168.2.10 2200 not working from the machine whereas it redirection is working from from other PC's

What is the gateway for your PCs and what is the gateway for 192.168.2.10?

pnmanojshenoy 03-28-2011 04:08 AM

Hello,

Thank you for your reply, the Gateway for the PC and the IPtables Machine are the same. as I told redirection is working fine if I try from another machine. but I am not abke to do the same from the IPtables machine using localhost or the IP it tells connection refused.

0.0.0.0 192.168.2.1 0.0.0.0 UG 100 0 0 eth0

manyrootsofallevil 03-28-2011 04:38 AM

Quote:

Originally Posted by pnmanojshenoy (Post 4305968)
Hello,

Thank you for your reply, the Gateway for the PC and the IPtables Machine are the same. as I told redirection is working fine if I try from another machine. but I am not abke to do the same from the IPtables machine using localhost or the IP it tells connection refused.

0.0.0.0 192.168.2.1 0.0.0.0 UG 100 0 0 eth0

My question was irrelevant, I was trying to replicate your setup but it had ipforwarding off. D'oh.

Have a look at this post http://www.linuxquestions.org/questi...-issue-487153/

In essence, you need the following

Code:

iptables -t nat -A OUTPUT -p tcp --dport 2200 -j DNAT --to 192.168.70.101

pnmanojshenoy 03-29-2011 12:03 AM

Hello,

I did check that before but was not working for me... but when I tried now it worked... had to flush Iptables two time, to get this worked..

iptables -t nat -F
iptables -F

Thank you.


All times are GMT -5. The time now is 11:02 AM.