LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 01-28-2009, 05:39 AM   #1
panic4all
LQ Newbie
 
Registered: Dec 2008
Posts: 2

Rep: Reputation: 0
Question Problem on iptables port forwarding


Hi, I have a DSL router that has a public IP 1.2.3.4 and it nat to a subnet 10.0.0.x, and under this net there's a slack 12.1 server (configured as DMZ) with two eths, eth0: 10.0.0.253 linked to router lan and eth1: 192.168.1.254, linked to another subnet (the real local lan whith some PCs).
The slack server is configured to nat subnet 192.168.1.254, to allow PCs browsing.
Now I had to forward a port from ext public IP (ex. port 8080) to an application server that is on the lan 192.168.1.x, and this machine has IP 192.168.1.10 (and the destionation port is for example port 23)
I used this script, but it doesn't work, have someone some suggestions on it? Thanks in advance!

#!/bin/sh
# setting vars
IPTABLES="/usr/sbin/iptables"
IP0=`10.0.0.253`
IP1=`192.168.1.254`
INTIP='192.168.1.10'
echo "1" > /proc/sys/net/ipv4/ip_forward

# startup rules
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -t nat -P PREROUTING ACCEPT
$IPTABLES -t nat -P POSTROUTING ACCEPT
$IPTABLES -t nat -P OUTPUT ACCEPT
$IPTABLES -t nat -P PREROUTING ACCEPT
$IPTABLES -t nat -P OUTPUT ACCEPT
$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
$IPTABLES -X
$IPTABLES -t nat -X
$IPTABLES -t mangle -X

# forward the traffic from the local network (MASQ)
$IPTABLES -t nat -A POSTROUTING -o eth0 -s $LRN/24 -d 0/0 -j MASQUERADE

# forward specified port
$IPTABLES -t filter -A INPUT -i eth0 -p tcp -d $IP0 --dport 8080 -j ACCEPT
$IPTABLES -t nat -A PREROUTING -i eth0 -p tcp -d $IP0 --dport 8080 -j DNAT --to $INTIP:23
$IPTABLES -A FORWARD -i eth0 -p tcp -d $INTIP --dport 23 -j ACCEPT

Last edited by panic4all; 01-29-2009 at 06:38 AM.
 
Old 01-30-2009, 05:01 AM   #2
rossonieri#1
Member
 
Registered: Jun 2007
Posts: 359

Rep: Reputation: 34
hi,

not too clear. on which machine did you put the script? eth 1 router or the DMZ slack?
'if' this script was on the router,
and assuming eth0 is internet-facing NIC, then
Code:
$IPTABLES -t nat -A PREROUTING -i eth0 -p tcp -d $IP0 --dport 8080 -j DNAT --to $INTIP:23
you dont need -d $IP0 - it will go nowhere since the incoming interface (internet) only know 1.2.3.4, and that -d $IP0 represents private address which is not internet-routable.

and, a bit complicated - but you should do a double DNAT which are 1 for the 1 router pointing to DMZ slack, and 1 for the DMZ slack pointing to internal server.

HTH.

Last edited by rossonieri#1; 01-30-2009 at 05:03 AM.
 
Old 01-30-2009, 10:22 AM   #3
panic4all
LQ Newbie
 
Registered: Dec 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Smile

Thanks rossonieri#1 for answer,
I'm on the slack server and I just found the answer: the unix server on the lan 192.68.1.x (I don't have a login on it...) has no default gateway (In fact I saw packets on two eths with tcpdump correctly formed...).
The two rules:
Code:
$IPTABLES -t nat -A PREROUTING -i eth0 -p tcp -d $IP0 --dport 8080 -j DNAT --to $INTIP:23
$IPTABLES -A FORWARD -i eth0 -p tcp -d $INTIP --dport 23 -j ACCEPT
are correct and now all rocks; I hope may be useful for someone.
 
  


Reply

Tags
iptables, portforward


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 port forwarding problem PeeCee-BW Linux - Networking 2 12-22-2008 03:48 AM
Port Forwarding Problem using IPTABLES ^vampire^ Linux - Security 1 10-12-2006 05:22 AM
iptables with port forwarding problem ... please help me rubenscript Linux - Networking 1 04-26-2006 05:51 PM
iptables problem.....port forwarding..... shahg_shahg Linux - Networking 1 03-22-2006 06:17 AM
IPTables port forwarding problem deadlydemon Linux - Security 2 04-25-2005 05:43 PM


All times are GMT -5. The time now is 07:14 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration