LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   IPTables routing internal requests (http://www.linuxquestions.org/questions/linux-networking-3/iptables-routing-internal-requests-4175452340/)

SernOne 03-01-2013 10:22 PM

IPTables routing internal requests
 
So I have a front end firewall using IP tables, it handles all requests coming in and talks down to the other boxes.

However I can not hit ports on my internal network that i can from the outside network for instance port 25 or 80.

Setup :
p3p1 - publicIP
p3p2 - 10.1.1.1

when do something like.
telnet MYpublicDomain.com 80

from an internal box i get connection refused.

here are my IPtables

[root@abby ~]# iptables -t nat -L -v -n
Chain PREROUTING (policy ACCEPT 1190 packets, 110K bytes)
pkts bytes target prot opt in out source destination
248 12896 DNAT tcp -- p3p1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:443 to:10.1.1.10
9 476 DNAT tcp -- p3p1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 to:10.1.1.10
0 0 DNAT tcp -- p3p1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:21 to:10.1.1.10
23 1380 DNAT tcp -- p3p1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:25 to:10.1.1.11
0 0 DNAT tcp -- p3p1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:110 to:10.1.1.11
19 1140 DNAT tcp -- p3p1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:143 to:10.1.1.11
0 0 DNAT tcp -- p3p1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:2222 to:10.1.1.10

Chain INPUT (policy ACCEPT 808 packets, 55937 bytes)
pkts bytes target prot opt in out source destination

Chain OUTPUT (policy ACCEPT 1843 packets, 128K bytes)
pkts bytes target prot opt in out source destination

Chain POSTROUTING (policy ACCEPT 1767 packets, 118K bytes)
pkts bytes target prot opt in out source destination
738 81101 MASQUERADE all -- * p3p1 0.0.0.0/0 0.0.0.0/0


Not sure what I am missing here
tried to do this
iptables -t nat -A PREROUTING -i p3p2 -p tcp -d PublicIP --dport 80 -j DNAT --to-destination 10.1.1.10

But the connection just hangs i can see it hit iptables but than it dies. Also i still get connection refused from the firewall box directly. Any help would be awesome i am lost on this.

thank you!

Shadow_7 03-02-2013 12:07 AM

Connections have multiple aspects.

A) a destination, like an IP address
B) a route, which is independent of any filtering.
C) a firewall which allows (or not) traffic to flow.

Most troubleshooting involves bypassing C) which isn't always a wise choice, but in some cases may be the only choice. Otherwise.

# ifconfig -a
# route -n

# iptables-save
# ebtables -t nat -L

Or whatever applies.

hamlindsza 03-02-2013 10:09 AM

iptables -t nat -A PREROUTING -i p3p2 -p tcp -d PublicIP --dport 80 -j DNAT --to-destination 10.1.1.10

in the above rule, u are specifying the input interface "-i p3p2" which i assume is the public interface. Hence you are able to access port 80 only from the public interface not the lan interface.

So to get access from the internal network, either do not specify the input interface "-i" or add another rule specifying the LAN interface.

SernOne 03-02-2013 07:37 PM

Quote:

Originally Posted by hamlindsza (Post 4903151)
iptables -t nat -A PREROUTING -i p3p2 -p tcp -d PublicIP --dport 80 -j DNAT --to-destination 10.1.1.10

in the above rule, u are specifying the input interface "-i p3p2" which i assume is the public interface. Hence you are able to access port 80 only from the public interface not the lan interface.

So to get access from the internal network, either do not specify the input interface "-i" or add another rule specifying the LAN interface.

See that's the weird part the p3p2 interface is the internal interface. What you saying is basically an any interface rule on that port and see what happens?

hamlindsza 03-02-2013 10:29 PM

Quote:

Originally Posted by SernOne (Post 4903412)
See that's the weird part the p3p2 interface is the internal interface. What you saying is basically an any interface rule on that port and see what happens?

Hmmm...Try adding a rule without specifying the interface, but specify the public ip.

Code:

iptables -t nat -I PREROUTING -p tcp -d PublicIP --dport 80 -j DNAT --to-destination 10.1.1.10:80

gmarthe 03-05-2013 03:04 PM

Hi Sernone,

This is what I believe is happening:

1) From within your network, you try to access your public IP on port 80.
2) Your latest DNAT rule on PREROUTING should work correctly : iptables -t nat -A PREROUTING -i p3p2 -p tcp -d PublicIP --dport 80 -j DNAT --to-destination 10.1.1.10
3) Now, you haven't shown us your FORWARD rules (iptables -vnL FORWARD) - but you will be forwarding from your p3p2 to p3p2 and back again, so you need something like this:
iptables -I FORWARD -i p3p2 -o p3p2 -j ACCEPT
4) This will allow your packets to hit the router and be forwarded back to 10.1.1.10 on your internal network.
5) However, assuming the IP address of your client machine is on that same network (10.1.1.0/24), you will have a small problem - ie, the web on 10.1.1.10 will receive your packets and answer directly to you (as it sees you are on the same network). Your machine will see packets arrive from 10.1.1.10 without the SYN bit set as if they were part of an existing connection and silently ignore them.
6) What you have to do is is SNAT on your router - iptables -t nat -A POSTROUTING -o p3p2 -j MASQUERADE
Thus 10.1.1.10 will always send responses back the way they arrived.

Hope this helps.

gmarthe 03-05-2013 05:16 PM

Just as an after thought, it's worth noting that if you put a MASQUERADE or SNAT rule on your internal interface without further qualification, all the log entries on your apache server will appear to come from your router; not very useful, I guess.
You could just change the MASQ rule I mentioned in the previous post as follows:

iptables -t nat -A POSTROUTING -o p3p2 -s 10.1.1.0/24 -j MASQUERADE


All times are GMT -5. The time now is 06:34 AM.