Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Linux > Linux Networking

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-17-2008, 06:59 PM
Bubba
 
Posts: n/a
Port forwarding question

Greetings to all,

Here is the issue that I do not know how to resolve. There is a Debian
based internet gateway with iptables firewall.

There are 3 servers currently running, all 3 with up and running web
servers (apache, apache2 and IIS). How can I direct traffic from the
Internet to the web server that is not on gateway, but in the local
network? In addition, how can enable users from the internet to use
*all* 3 web servers at their discretion (for example, when user writes
www.mydomain.net/server1 - IIS on local IP x.x.x.y server pops out,
www.mydomain.net/server2 -apache2 server on local IP x.x.x.z pops out,
etc...)?

I hope I was clear enough. :)

TIA!

--
Everything will be okay
in the end.
If it's not okay
it's not the end!
Reply With Quote
  #2 (permalink)  
Old 03-17-2008, 07:24 PM
Nicolas BOUTHORS
 
Posts: n/a
Re: Port forwarding question

Bubba a écrit :
> There are 3 servers currently running, all 3 with up and running web
> servers (apache, apache2 and IIS). How can I direct traffic from the
> Internet to the web server that is not on gateway, but in the local
> network? In addition, how can enable users from the internet to use
> *all* 3 web servers at their discretion (for example, when user writes
> www.mydomain.net/server1 - IIS on local IP x.x.x.y server pops out,
> www.mydomain.net/server2 -apache2 server on local IP x.x.x.z pops out,
> etc...)?


If you want to do it based on the URL, then you need to use Apache on
the gateway with mod_rewrite. Something like this :

RewriteEngine on
RewriteRule /server1/(.*) http://10.1.2.3/$1 [proxy,qsappend,last]
RewriteRule /server2/(.*) http://10.1.2.4/$1 [proxy,qsappend,last]
RewriteRule /server3/(.*) http://10.1.2.5/$1 [proxy,qsappend,last]

If you want to do it with iptables/netfilter then you could do something
like this :

iptables -t nat -A PREROUTING -p tcp --dport 8080 -j DNAT --to 10.1.2.3:80
iptables -t nat -A PREROUTING -p tcp --dport 8081 -j DNAT --to 10.1.2.4:80
iptables -t nat -A PREROUTING -p tcp --dport 8082 -j DNAT --to 10.1.2.5:80

Cheers,

Nico


--
Nicolas Bouthors -=- Tel : 06 20 71 62 34 -=- Fax : 01 46 87 21 99
NBi SARL -=- http://nbi.fr -=- nbouthors@nbi.fr
Reply With Quote
  #3 (permalink)  
Old 03-17-2008, 07:53 PM
Bubba
 
Posts: n/a
Re: Port forwarding question

Nicolas BOUTHORS's log on stardate 17 ožu 2008

> If you want to do it based on the URL, then you need to use Apache on
> the gateway with mod_rewrite. Something like this :
>
> RewriteEngine on
> RewriteRule /server1/(.*) http://10.1.2.3/$1 [proxy,qsappend,last]
> RewriteRule /server2/(.*) http://10.1.2.4/$1 [proxy,qsappend,last]
> RewriteRule /server3/(.*) http://10.1.2.5/$1 [proxy,qsappend,last]


I might try that one, thx.

> If you want to do it with iptables/netfilter then you could do
> something like this :
>
> iptables -t nat -A PREROUTING -p tcp --dport 8080 -j DNAT --to 10.1.2.3:80
> iptables -t nat -A PREROUTING -p tcp --dport 8081 -j DNAT --to 10.1.2.4:80
> iptables -t nat -A PREROUTING -p tcp --dport 8082 -j DNAT --to 10.1.2.5:80


Here's my whole iptables:

#!/bin/sh
#Flush current rules
iptables=/sbin/iptables
$iptables -F
$iptables -t nat -F

#Setup default policies to handle unmatched traffic
$iptables -P INPUT ACCEPT
$iptables -P OUTPUT ACCEPT
$iptables -P FORWARD DROP

LAN="eth1"
WAN="ppp0"

#Then we lock our services so they only work from the LAN
$iptables -I INPUT 1 -i ${LAN} -j ACCEPT
$iptables -I INPUT 1 -i lo -j ACCEPT
$iptables -A INPUT -p UDP --dport bootps -i ! ${LAN} -j REJECT
$iptables -A INPUT -p UDP --dport domain -i ! ${LAN} -j REJECT
$iptables -A INPUT -p UDP --dport 123 -i ${LAN} -j ACCEPT

#SSH access
$iptables -A INPUT -p TCP --dport ssh -i ${WAN} -j ACCEPT

#HTTP access
$iptables -A INPUT -p TCP --dport 80 -i ${WAN} -j ACCEPT

#Drop TCP / UDP packets to privileged ports
$iptables -A INPUT -p TCP -i ! ${LAN} -d 0/0 --dport 0:1023 -j DROP
$iptables -A INPUT -p UDP -i ! ${LAN} -d 0/0 --dport 0:1023 -j DROP

#NAT
$iptables -I FORWARD -i ${LAN} -d 192.168.1.0/255.255.255.0 -j DROP
$iptables -A FORWARD -i ${LAN} -s 192.168.1.0/255.255.255.0 -j ACCEPT
$iptables -A FORWARD -i ${WAN} -d 192.168.1.0/255.255.255.0 -j ACCEPT
$iptables -t nat -A POSTROUTING -o ${WAN} -j MASQUERADE

#Port forward is OK!
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/ip_dynaddr

#Port forwarding
$iptables -t nat -A PREROUTING -p tcp --dport 6881:6889 -i ${WAN} -j DNAT --to 192.168.1.2

I already tried with port forwarding similar to yours, but failed. Any
idea why? I did something like this:

$iptables -t nat -A PREROUTING -p tcp --dport 80 -i ${WAN} -j DNAT --to 192.168.1.252

however, regardless of that, I still get the web server from the
gateway when I try to connect from the internet to my domain.


--
Everything will be okay
in the end.
If it's not okay
it's not the end!
Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Linux > Linux Networking


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:16 AM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Free Credit Reports | Actress | MPAA | Debt Consolidation | Xbox Mod Chip



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114