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 12-13-2010, 04:15 PM   #1
bob77
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Rep: Reputation: 0
Iptables not forwaring to another ip


I have 2 Linux boxes one acting as a router with a direct connection to the internet, second as a server using the first box as a gateway to the internet.

I need to forward requests that I get from the outside to port 8400 to my internal server box at 192.168.0.7:8400

Router IP 192.168.0.5
Server IP 192.168.0.7

iptables -t nat -A PREROUTING -p tcp -d [internet ip] --dport 8400 -j DNAT --to-destination 192.168.0.7:8400 < Won't work
iptables -t nat -A PREROUTING -p tcp -d [internet ip] --dport 8400 -j DNAT --to-destination 192.168.0.5:8400 < Will work

These rules are on the router (192.168.0.5)

I've been trying to find a solution for hours with no success.

Basically the problem is I can forward ports on the same box but not to a different ip..

Any help would be greatly appreciated.
 
Old 12-13-2010, 04:37 PM   #2
bob77
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Well after HOURS of trying I finally figured it out,

iptables -t nat -A POSTROUTING -d 192.168.0.7 -j MASQUERADE
iptables -t nat -A PREROUTING -p tcp -d [internet ip] --dport 8400 -j DNAT --to-destination 192.168.0.7:8400

Adding iptables -t nat -A POSTROUTING -d 192.168.0.7 -j MASQUERADE
did the trick, I'll leave this here in case someone else has the same problem.
 
  


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
Lipipq(iptables) . How do I redirect captured packet to another address with iptables inet905 Programming 0 05-25-2010 01:20 AM
On what basis CHAIN integer values are generated in IPtables under iptables file? haariseshu Linux - Server 3 11-05-2009 04:25 AM
iptables v1.2.9: Unknown arg `/sbin/iptables' Try `iptables -h' or 'iptables --help' Niceman2005 Linux - Security 4 12-29-2005 08:20 PM
IPtables Log Analyzer from http://www.gege.org/iptables/ brainlego Linux - Software 0 08-11-2003 06:08 AM
My iptables script is /etc/sysconfig/iptables. How do i make this baby execute on boo ForumKid Linux - General 3 01-22-2002 07:36 AM

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

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