LinuxQuestions.org
Review your favorite Linux distribution.
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 08-07-2006, 03:49 AM   #1
mkirc
Member
 
Registered: Apr 2006
Location: Vienna-Austria
Distribution: Suse 10.x, Fedora, DSL
Posts: 63

Rep: Reputation: 15
Iptables DNAT on Suse 10.0


Hello,

I'd like to enable an internal http-server to the external net.
My approach: All requests to a dummy-port (i.e. 8888) on my Standard-Gateway, which is the only one visible to the external net) will be redirected to the http-server

I tried the following:

iptables -t nat -A PREROUTING -d ${IP_GATEWAY} -p tcp --dport 8888 -j DNAT --to-destination ${IP_HTTP}:80

Nothing happens, requests like http://IP_GATEWAY:8888 fail ?

Can anyone help, any comment is appreciated.

Thanks in advance,
Michael
 
Old 08-07-2006, 05:07 AM   #2
peter_robb
Senior Member
 
Registered: Feb 2002
Location: Szczecin, Poland
Distribution: Gentoo, Debian
Posts: 2,458

Rep: Reputation: 48
The webserver gets the port 8888 in the http headers and can't find a host/domain that matches that port.
 
Old 08-07-2006, 05:39 AM   #3
mkirc
Member
 
Registered: Apr 2006
Location: Vienna-Austria
Distribution: Suse 10.x, Fedora, DSL
Posts: 63

Original Poster
Rep: Reputation: 15
Thanks for your reply !
If I understand you correcdtly, my approach fails, because the port-number is in the http-header as well ?
Would it help to configure the http-server to listen on port 8888 instead of 80 ?
 
Old 08-07-2006, 09:47 AM   #4
peter_robb
Senior Member
 
Registered: Feb 2002
Location: Szczecin, Poland
Distribution: Gentoo, Debian
Posts: 2,458

Rep: Reputation: 48
That would make it work well.

Add a virtualhost that listens on port 8888
and also add a Listen directive for port 8888 in httpd.conf
Leave the default settings of port 80, just add these.

Then add the NAT to the ip address, eg
iptables -t nat -A PREROUTING -i ${EXTIF} -p tcp --dport 8888 -j DNAT --to-destination ${IP_HTTP}

Last edited by peter_robb; 08-07-2006 at 09:50 AM.
 
Old 08-13-2006, 05:28 AM   #5
mkirc
Member
 
Registered: Apr 2006
Location: Vienna-Austria
Distribution: Suse 10.x, Fedora, DSL
Posts: 63

Original Poster
Rep: Reputation: 15
Hello Peter !

It took me a while to implement your advice, but the internal http-server run into more basic problems. Anyway now its up again (its a camera btw), I changed the port of the webserver to 8888, but its still the same effect, no packets from outside are forwarded to the internal http-server.

I found some hits regarding iptables DNAT, that it has to be accompanied by a SNAT-Statement like:
iptables -t nat -A PREROUTING -d ${IP_GATEWAY} -p tcp --dport 8888 -j DNAT
--to-destination ${IP_HTTP}
Accomplishing SNAT:
iptables -t nat -A POSTROUTING -s ${IP_HTTP} -p tcp --sport 8888 -j SNAT
--to-source ${IP_GATEWAY}
I tried this....but did not change anything !

On the other hand iptables-doc says that I need only to reroute the first (incoming) packet, all others follow "automatically".

Maybe you have an idea what could be wrong ?

Thanks anyway,
Michael
 
Old 08-14-2006, 08:29 AM   #6
peter_robb
Senior Member
 
Registered: Feb 2002
Location: Szczecin, Poland
Distribution: Gentoo, Debian
Posts: 2,458

Rep: Reputation: 48
You only need the DNAT rule. The snat is handled internally by netfilter.

Avoid using -d ip.add.ress in a DNAT rule.
Rather, use an interface specification, ie -i eth~
This way you can be sure exactly which packets are being changed.
 
  


Reply


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
why does iptables DNAT fail? eantoranz Linux - Security 12 08-25-2006 01:11 PM
Help with iptables/DNAT/forwarding lohb1ac Linux - Networking 2 12-05-2005 08:48 AM
iptables DNAT pshepperd Linux - Security 1 05-22-2004 03:56 PM
DNAT question (Iptables) wilsonmau Linux - Networking 1 06-06-2003 06:50 AM
iptables DNAT bentz Linux - Networking 15 05-19-2003 01:17 PM

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

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