LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 03-01-2013, 10:22 PM   #1
SernOne
Member
 
Registered: Oct 2012
Posts: 33

Rep: Reputation: Disabled
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!
 
Old 03-02-2013, 12:07 AM   #2
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
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.
 
Old 03-02-2013, 10:09 AM   #3
hamlindsza
Member
 
Registered: Aug 2012
Distribution: Debian, CentOS
Posts: 74

Rep: Reputation: Disabled
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.
 
Old 03-02-2013, 07:37 PM   #4
SernOne
Member
 
Registered: Oct 2012
Posts: 33

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hamlindsza View Post
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?
 
Old 03-02-2013, 10:29 PM   #5
hamlindsza
Member
 
Registered: Aug 2012
Distribution: Debian, CentOS
Posts: 74

Rep: Reputation: Disabled
Quote:
Originally Posted by SernOne View Post
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
 
Old 03-05-2013, 03:04 PM   #6
gmarthe
LQ Newbie
 
Registered: Mar 2013
Posts: 3

Rep: Reputation: Disabled
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.
 
Old 03-05-2013, 05:16 PM   #7
gmarthe
LQ Newbie
 
Registered: Mar 2013
Posts: 3

Rep: Reputation: Disabled
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables not routing internal network brunoschwartz Linux - Server 3 06-29-2012 11:46 AM
Keep Apache from going beyond the LAN on internal requests crispyleif Linux - Server 1 04-18-2009 03:54 PM
Redirecting apache2 http requests to internal ip coopea Linux - Networking 1 09-21-2008 02:59 PM
routing requests to internal computer anthill Linux - Server 6 10-08-2007 03:09 AM
Routing incoming requests to different IP anthill Linux - Networking 1 09-18-2007 11:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration