Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have two questions.

Question 1: My debian machine has interface eth3 with ip 192.168.57.28. If someone tries to connect to 192.168.57.28:1234 how do I redirect the request to another machine: 192.168.57.25:80?

Question 2: If my debian machine has two interfaces: eth3 with 192.168.57.28 and ppp0 with some dynamic IP and someone tries to connect via ppp0 on port 1234, how do I redirect the request to 192.168.57.25:80?

I have tried this:

iptables -t nat -A PREROUTING -p tcp --dport 1234 -j DNAT --to-destination 192.168.57.25:80
echo 1 > /proc/sys/net/ipv4/ip_forward

but it does not work.

share|improve this question
    
I would highly recommend reading [this tutorial](frozentux .net/documents/iptables-tutorial/) on iptables but the site appears to be down at the moment. –  kostix Aug 21 '13 at 11:11

1 Answer 1

Ok the rule looks fine, but you have to remember that packets generated in that machine do not go through PREROUTING. If said machine that holds the iptables in question needs to also redirect it's own traffic the same way, you need to put the same rule to OUTPUT. See iptables-extensions DNAT, it's valid both in OUTPUT and PREROUTING.

Another this that might come into question is filtering. Make sure you also allow said traffic to pass through the machine both ways.

Third thing is that you may also need to MASQUERADE the traffic to that destination in POSTROUTING for a route home.

I can't tell where the packets are lost based on information present. Use tcpdump to see where the packets fly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.