All of lore.kernel.org
 help / color / mirror / Atom feed
* locally access server behind firewall
@ 2004-09-01 17:53 Tom
  2004-09-01 18:05 ` John A. Sullivan III
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Tom @ 2004-09-01 17:53 UTC (permalink / raw)
  To: netfilter

Hi,

I have a linux firewall (iptables), and a linux server with apache 
behind that firewall. My provider blocks ports below 1024, so I have a 
prerouting-rule that redirects traffic like this:

$IPTABLES -A PREROUTING -t nat -i $WWW p tcp -d $EXTIP --dport 8888 -j 
DNAT --to $SERVER:80

I also have 2 forward-rules:

$IPTABLES -A FORWARD -i $WWW -o $LAN -p tcp --dport 80 -j ACCEPT
$IPTABLES -A FORWARD -i $LAN -o $WWW -p tcp --sport 80 -j ACCEPT

and I have these two lines to allow my local pc's to connect to the 
firewall with ssh and stuff like that:
$IPTABLES -A INPUT -i $LAN -s $INTLAN -j ACCEPT
$IPTABLES -A OUTPUT -o $LAN -d $INTLAN -j ACCEPT


where:
  $EXTIP = my external IP address
  $WWW is eth1
  $LAN is eth0
  $SERVER = my server's internal IP address.
  $INTLAN = "192.168.0.0/24"

This works really well when I try to connect from the outside to my 
webserver. But, if I try to connect to http://myserver.com:8888 from the 
internal network (or from my server itself), I always get 'connection 
refused'. I'm pretty sure I need some other rules, but can someone 
please help me in the good direction here? Thanks a lot!!



PS: Here's a little drawing of the situation:

SERVER (eth0) <----> (eth0) GATEWAY-PC (eth1) <----> internet



^ permalink raw reply	[flat|nested] 8+ messages in thread
* RE: locally access server behind firewall
@ 2004-09-01 18:20 Daniel Chemko
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Chemko @ 2004-09-01 18:20 UTC (permalink / raw)
  To: Deepak Seshadri, Tom, netfilter

Deepak Seshadri wrote:
> Hi Tom,
> 
> I think your Apache server is expecting connections on port 80 & your
> Nat'ing will occur only if the packet comes in form the $WWW
> interface. Since you are on the local LAN the packets are not Nat'ted
> and hence you get the connection refused from the server as it is
> getting requests on a port where no application is listening.
> 
> You don't need any rule, just type http://myserver.com within the LAN.

Problem:

You root problem is that your resolving myserver.com as an intrernet
address. The client connects to the GW (linux) in order to get routed to
the box. The linux machine passes the connection request on to
${internal_www} server without making any changes. The Server reads the
client's source address (knowing its in the internal network) and passes
it back to the client directly. So, your route  now looks like this:

Client->Firewall->Server->Client

THIS DOES NOT WORK
The every packet after the SYN will be tossed because the firewall never
received the corresponding SYN-ACK packet from ${internal_www}


Solution:

There are two ways to accomplish this: The right way and the wrong way.
The easiest way is just to implement the lines below.
	
	iptables -t nat -A POSTROUTING --destination ${internal_www} -p
tcp --dport 80 -j SNAT ${internal_gw_ip}
	# In case this isn't covered by other rules, you need a loopback
rule for that network interface
	iptables -A FORWARD -i ${internal_if} -o ${internal_if} -j
ACCEPT

The other solution is to use Split DNS. Where myserver.com resolves to
an internal DNS address like 192.168.1.1 instead of 24.1.1.1. There's a
lot of information about split-dns on the internet. I'm not going to
repeat it here again and again...



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-09-01 18:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-01 17:53 locally access server behind firewall Tom
2004-09-01 18:05 ` John A. Sullivan III
2004-09-01 18:11   ` Tom
2004-09-01 18:08 ` Jason Opperisano
2004-09-01 18:13 ` Deepak Seshadri
2004-09-01 18:17 ` Alistair Tonner
2004-09-01 18:30   ` Tom
  -- strict thread matches above, loose matches on Subject: below --
2004-09-01 18:20 Daniel Chemko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.