LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 06-20-2008, 08:44 AM   #1
PetruM
LQ Newbie
 
Registered: Apr 2006
Location: Sweden
Distribution: Slackware, Ubuntu 22.04 LTS
Posts: 19

Rep: Reputation: Disabled
Question Forwarding an IP to a different port


Hello.

Code:
iptables -t nat -A PREROUTING -p tcp --dport 23 -j DNAT --to-destination 192.168.0.41
I understand that the above command forwards connections on port 23 to 192.168.0.41 on port 23. This isn't exactly what I need. I'm looking for something that will allow me to forward connections on port 23 to 192.168.0.41 on port 80, for example.

Any help is appreciated.
 
Old 06-20-2008, 09:00 AM   #2
avalonit
Member
 
Registered: Jun 2008
Posts: 81

Rep: Reputation: 19
192.168.0.41:80 works?
 
Old 06-20-2008, 09:51 AM   #3
PetruM
LQ Newbie
 
Registered: Apr 2006
Location: Sweden
Distribution: Slackware, Ubuntu 22.04 LTS
Posts: 19

Original Poster
Rep: Reputation: Disabled
I'll give it a try soon. Thanks!
 
Old 06-20-2008, 05:21 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
This might work.
Code:
# Set WAN to receiving interface
WAN=eth0
iptables -t nat -A PREROUTING -p tcp -i $WAN --dport 23 -j DNAT --to 192.168.0.41:80
iptables -A FORWARD -p tcp -i $WAN -d 192.168.0.41 --dport 80 -j ACCEPT
Besides mangling the packet to make it look acceptable to the target host (what nat + PREROUTING does), you also need a rule to make it get sent there (what filter + FORWARD does).
--- rod.
 
Old 06-21-2008, 07:38 AM   #5
PetruM
LQ Newbie
 
Registered: Apr 2006
Location: Sweden
Distribution: Slackware, Ubuntu 22.04 LTS
Posts: 19

Original Poster
Rep: Reputation: Disabled
The first one seems to do the job.
Thanks to both!
 
Old 06-23-2008, 11:46 AM   #6
wag2639
LQ Newbie
 
Registered: Mar 2008
Posts: 7

Rep: Reputation: 0
I'm trying to do this with an SSH port and it doesn't seem to be working (swapping out port 80 with port 22 and using the appropriate IP).

Am I suppose to put the rules into a config file or something.

Thanks
 
Old 06-23-2008, 03:57 PM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
You can run the commands, as root, from a commandline. Most installations have a script or scripts to configure firewalls, routers, etc., and the commands could be placed in an appropriate spot within one of those scripts. It would be up to you to figure out where they would best fit. Many such scripts are built from GUI tools or canned firewall scripts. Using the GUI or the documentation & comments embedded in existing scripts might give you some clues. The commands that I provided came from the homeLANSecurity package that I use.
--- rod.
 
  


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
Unable to allocate port with port forwarding software djeepp Linux - Networking 3 01-29-2008 07:28 AM
port forwarding on Belkin 4-port Cable/DSL Gateway Router sycamorex Linux - Networking 5 03-05-2007 03:27 PM
IPCHAINS port forwarding and IPTABLES port forwarding ediestajr Linux - Networking 26 01-14-2007 07:35 PM
Simple Port Forwarding Firewall - not forwarding MadTurki Linux - Security 14 04-09-2006 12:08 PM
port forwarding and packet forwarding syrtsardo Linux - Newbie 2 07-03-2003 10:37 AM

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

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