LinuxQuestions.org
Review your favorite Linux distribution.
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-26-2003, 11:12 AM   #1
darchon
Member
 
Registered: Mar 2003
Location: Storuman@Sweden
Distribution: Gentoo
Posts: 30

Rep: Reputation: 15
port routing problem


Ilustration:

Internet
|
eth2
Linux RH 8.0 (with 3 nic)
| \
| eth0 (192.168.0.1) <=> Win 2k (192.168.0.10) (Ftp server)
|
eth1(192.168.0.3) <=> Win 2k (192.168.0.11) (Http server)


Internet sharing is done with a iptable script
work fine

My problem(s):
-port forwarding:
im trying to forward all incoming calls on port 80 to port 80 on the httpserver and all 21 to ftp

i have tried this line (and similar)
)
Code:
iptables -N INPUT -t nat -p tcp -i eth2 --dport 80 -j DNAT --to 192.168.0.10:80
but i cant get it working

-lan between the two win2k is not working
i can see them in the workgroup but i cant connect. (no ping is possible ether)
 
Old 03-26-2003, 12:02 PM   #2
Pcghost
Senior Member
 
Registered: Feb 2003
Location: The Arctic
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820

Rep: Reputation: 46
Try the following in your script

echo 1 > /proc/sys/net/ipv4/ip_forward

iptables -t nat -A PREROUTING -p tcp -i eth2 --dport 80 -j DNAT --to-destination 192.168.0.10:80

iptables -A FORWARD -i eth2 -p tcp -d 192.168.0.10 --dport 80 -j ACCEPT
 
Old 03-26-2003, 12:40 PM   #3
darchon
Member
 
Registered: Mar 2003
Location: Storuman@Sweden
Distribution: Gentoo
Posts: 30

Original Poster
Rep: Reputation: 15
this is my firewall script:

# rc.firewall-2.4
FWVER=0.73

echo -e "\n\nLoading simple rc.firewall version $FWVER..\n"

IPTABLES=/sbin/iptables
DEPMOD=/sbin/depmod
INSMOD=/sbin/insmod

EXTIF="eth2"
INTIF="eth1"
INTIF2="eth0"
echo " External Interface: $EXTIF"
echo " Internal Interface: $INTIF"
echo " Internal Interface: $INTIF2"

echo -en " loading modules: "

echo " - Verifying that all kernel modules are ok"
$DEPMOD -a

echo "---------------------------------------------------------------------"

echo -en "ip_tables, "
$INSMOD ip_tables

echo -en "ip_conntrack, "
$INSMOD ip_conntrack

echo -en "ip_conntrack_ftp, "
$INSMOD ip_conntrack_ftp

echo -en "ip_conntrack_irc, "
$INSMOD ip_conntrack_irc

echo -en "iptable_nat, "
$INSMOD iptable_nat

echo -en "ip_nat_ftp, "
$INSMOD ip_nat_ftp

#echo -e "ip_nat_irc"
#$INSMOD ip_nat_irc

echo "----------------------------------------------------------------------"
echo -e " Done loading modules.\n"

echo " Enabling forwarding.."
echo "1" > /proc/sys/net/ipv4/ip_forward

echo " Enabling DynamicAddr.."
echo "1" > /proc/sys/net/ipv4/ip_dynaddr


#Clearing any previous configuration
# Unless specified, the defaults for INPUT and OUTPUT is ACCEPT
# The default for FORWARD is DROP (REJECT is not a valid policy)
echo " Clearing any existing rules and setting default policy.."
$IPTABLES -P INPUT ACCEPT
$IPTABLES -F INPUT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F OUTPUT
$IPTABLES -P FORWARD DROP
$IPTABLES -F FORWARD
$IPTABLES -t nat -F

$IPTABLES -t nat -A PREROUTING -p tcp -i eth2 --dport 80 -j DNAT --to-destination 192.168.0.10:80
$IPTABLES -A FORWARD -i eth2 -p tcp -d 192.168.0.10 --dport 80 -j ACCEPT

echo " FWD: Allow all connections OUT and only existing and related ones IN"
$IPTABLES -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $EXTIF -o $INTIF2 -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT
$IPTABLES -A FORWARD -i $INTIF2 -o $EXTIF -j ACCEPT

$IPTABLES -A FORWARD -j LOG

echo " Enabling SNAT (MASQUERADE) functionality on $EXTIF"
$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

echo -e "\nrc.firewall-2.4 v$FWVER done.\n"
 
Old 04-01-2003, 03:33 AM   #4
peter_robb
Senior Member
 
Registered: Feb 2002
Location: Szczecin, Poland
Distribution: Gentoo, Debian
Posts: 2,458

Rep: Reputation: 48
eth0 & eth1 must be on different subnets otherwise the routing table won't know where to return the packets to. eg

eth0 = 192.168.0.1 netmask 255.255.255.0
ftp server = 192.168.0.10 netmask 255.255.255.0 gateway = 192.168.0.1
eth1 = 192.168.1.1 netmask 255.255.255.0
http server = 192.168.1.11 netmask 255.255.255.0 gateway = 192.168.1.1

Unless you have a special reason to keep the servers apart, put them on the same card. It will save having to make complicated dmz rules to stop them talking to each other.
 
Old 04-01-2003, 03:48 AM   #5
darchon
Member
 
Registered: Mar 2003
Location: Storuman@Sweden
Distribution: Gentoo
Posts: 30

Original Poster
Rep: Reputation: 15
I got it working... now port forwarding from outside is working but i cant make the server forward computers inside the lan to my httpserver ???

The conection between the two win2k computers were done by changing the lines
Code:
echo " FWD: Allow all connections OUT and only existing and related ones IN"
$IPTABLES -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $EXTIF -o $INTIF2 -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT
$IPTABLES -A FORWARD -i $INTIF2 -o $EXTIF -j ACCEPT

---to this----

echo " FWD: Allow all connections OUT and only existing and related ones IN"
$IPTABLES -A FORWARD -i $EXTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $INTIF -j ACCEPT
$IPTABLES -A FORWARD -i $INTIF2 -j ACCEPT
Routing tables now knows were to forward by adding lines with "route add" in both linux and the two win2k pc's

Last edited by darchon; 04-01-2003 at 03:50 AM.
 
  


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
Port based routing neos Linux - Networking 1 09-21-2005 01:15 PM
routing port 80 bm1 Linux - Hardware 3 12-20-2003 01:55 PM
particular port routing for a nat bobster666 Linux - Networking 4 01-18-2003 06:28 PM
routing on a specific port stapper Linux - Networking 0 10-10-2002 01:08 PM
Port Routing/mapping Fuigus Linux - Networking 1 09-14-2001 04:29 AM

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

All times are GMT -5. The time now is 05:01 PM.

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