LinuxQuestions.org
Visit Jeremy's Blog.
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 04-21-2006, 05:13 PM   #1
mtndew
LQ Newbie
 
Registered: Jan 2006
Distribution: Fedora Core 5
Posts: 13

Rep: Reputation: 0
iptables to redirect ports?


Hi all,

I'm working with a poorly-written closed source program right now that interfaces with a webstore. The configuration has the following values only:

MySQL Server, MySQL Username, MySQL Password, MySQL Database, FTP Username, FTP Password, FTP Path

Notice there is NO FTP server. Using ethereal I have determined that it uses the same IP address as the MySQL server. Unfortunately, MySQL is on a different server (apparently this company doesn't think doing so is possible!)

So my question to the linux network experts is, How can I use iptables to redirect port 21 to one server, and port 3306 to another server? The FTP and MySQL servers are not on the LAN, btw, they are on the WAN.

What I am hoping to do is insert a LAN IP into this program for the MySQL server, which would be that of my Linux box, and have it redirect to the WAN IPs based on the ports. I am fairly sure this can be done, but if not just say so.

Thanks for the help you guys provide here!
 
Old 04-21-2006, 07:10 PM   #2
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
I'm sure you've looked up iptables port forwarding, and though this resource is for internal forwarding and not redirects, it may be able to give you some ideas: http://www.hackorama.com/network/portfwd.shtml
 
Old 04-21-2006, 07:37 PM   #3
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Rep: Reputation: 30
Code:
OTHER="216.239.59.104"
YOU="10.0.0.1"
$WAN="ppp0"

iptables -t nat -A PREROUTING -p tcp -i $WAN -d $YOU --dport 3306 -j DNAT --to $OTHER:3306
/sbin/iptables -A FORWARD -p tcp -i eth0 -d $YOU --dport 3306 -j ACCEPT
Repeat as needed.
 
Old 04-21-2006, 07:42 PM   #4
zaichik
Member
 
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
Hi mntdew,

I don't think this is going to work for you. It looks to me as though the program is designed to run on the FTP server, which is why there is no possibility of specifying it; it's assumed to be localhost.

I might be wrong, but the way I envision your set up is Box1 is running the program that interfaces with the webstore; Box2 has the FTP server on it, and Box3 is running MySQL. You want the FTP traffic that Box1 receives to be forwarded to Box2 via iptables, while the MySQL traffic can be handled by the program (since the MySQL host server can be configured).

The problem I see is this: If the program needs to be told the FTP username, password, and path, it seems to me that information will not be provided by the remote users. Thus, you could (possibly) forward the port 21 traffic to a different host, perhaps using:
Code:
iptables -A PREROUTING -t nat -p -tcp -d $PUBLICIP --dport 21 -j DNAT --to $OTHERHOSTIP:21
(disclaimer -- untested)

However, *if* that works, the packets so forwarded will not have the information needed to establish and maintain an FTP session: If they did, then why does the program require that configuration information? Since iptables works at a (much) lower level, the program will not ever see the traffic forwarded off by iptables. So why ask for FTP information at all?

If you cannot specify the FTP host, then the FTP host must either be hard-coded, or be assumed to be the localhost, or is configured elsewhere. If it is the localhost (from my understanding above, Box2), then...why use FTP at all?

Or maybe I'm missing something...it *has* been a rather long day.
 
Old 04-21-2006, 10:03 PM   #5
mtndew
LQ Newbie
 
Registered: Jan 2006
Distribution: Fedora Core 5
Posts: 13

Original Poster
Rep: Reputation: 0
Alright, thanks all, I figured it out from the above informations. The FTP server uses the same server as the mysql. I've confirmed this by running ethereal and changing the mysql server and watching the IP stay the same as the SQL server for each.
 
  


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:redirect ports except for packets destined for fierwall(upto 256 ip) itself mmshekiba Linux - Security 1 02-02-2006 12:08 PM
iptables redirect patvrs Linux - Networking 15 08-02-2005 08:31 AM
iptables redirect _ben_deb_ Linux - Networking 7 11-13-2004 05:06 AM
iptables redirect slack Linux - Networking 0 06-17-2002 04:04 AM
iptables redirect bhartnett Linux - Networking 1 09-26-2001 09:11 PM

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

All times are GMT -5. The time now is 04:47 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