IPTables Port forwarding rules works only for some hosts
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
IPTables Port forwarding rules does not work in internal network
I have the following iptables rules on proxy host, which forwards traffic to Server:
iptables -t nat -A PREROUTING -d $host_ip -i eth0 -p tcp -m tcp --dport $host_port -j DNAT --to-destination $server_ip:$server_port
iptables -t nat -A POSTROUTING -p tcp --dport $server_port -d $server_ip -j SNAT --to $host_ip
For one server(call it A), when i try to connect with echo client using proxy host_ip:host_port it works fine and client is connecting to server A, server_ip:server_port.
For other server(call it B), when i try to connect with echo client using proxy host_ip:host_port it does not work and there is a strange behavior.
Connection success rate of echo client is about 1%. About 100 attempts, one is successful. Period of successful attempts is not regular, it can be successful 1 of 300, or 3 of 100.
• Tcpdump logs were collected on proxy host and server. The analysis of these logs showed that the proxy server forwards traffic to server, server sends a response, but proxy server does not receive it (i.e. it is visible in the server dump that the response is sent to proxy, but there’s no corresponding packet in the proxy dump).
• An unexplained correlation was found: when an attempt is done to connect other client to the same echo-server (simultaneously with running echo-client), responses from the echo-server are received successfully by the echo-client.
What can be root cause of this issue? Should we find the problems on server B or on proxy server? Please, help.
The issue is that iptables port forwarding rules works only for external connections and not for connections in internal network. It's called nat loopback. I have tried to set these rules:
* iptables -t nat -A PREROUTING -d $host_ip -i eth0 -p tcp -m tcp --dport $host_port -j DNAT --to-destination $server_ip:$server_port
* iptables -t nat -A POSTROUTING -s $source_ip -p tcp --dport $server_port -d $server_ip -j SNAT --to $host_ip
Postrouting rules will applies only for one machine, but it does not help to solve the issue, client connection from $source_ip is always freezes at the same place.