Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-03-2004, 07:54 AM
|
#1
|
Senior Member
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Rep:
|
why does iptables DNAT fail?
Hello, guys!
I have an issue with iptables right now.
I want my box to forward packets comming into it (no matter the destination) sent to smtp to a given host.
I think that would be:
Code:
iptables -t nat -A PREROUTING -t tcp --dport smtp -j DNAT --to-destination anotherhost
Correct me if I'm wrong but with that line I'm telling iptables to change the packet's destination IP adress even before the linux box considers routing and then it would forward the packets, right?
The other thing I did was:
echo "1" > /proc/sys/net/ipv4/ip_forward
but after doing this two things, the trick doesn't work. What's wrong?
|
|
|
09-03-2004, 12:21 PM
|
#2
|
Senior Member
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791
Rep:
|
Quote:
iptables -t nat -A PREROUTING -t tcp --dport smtp -j DNAT --to-destination anotherhost
|
it should be -p tcp instead of -t tcp
hope you have the FORWARD rules too.
|
|
|
09-03-2004, 02:48 PM
|
#3
|
Senior Member
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Original Poster
Rep:
|
Oh, man... that's not the problem. I wrote it -p tcp... just mispelled when I posted here.
I just read that NOT SNATing after DNATing can be a problem depening on the circumstances... could that be the problem?
Last edited by eantoranz; 09-03-2004 at 02:53 PM.
|
|
|
09-03-2004, 04:51 PM
|
#4
|
Member
Registered: Oct 2003
Distribution: Redhat 9
Posts: 138
Rep:
|
I port forward on my firewall as well and this is what I have, hope it works
try this:
iptables -A PREROUTING -t nat -p tcp -s <anywhere> -d <ip address on router/firewall> --dport <port you are forwarding to> -j DNAT --to-destination <ip you are forwarding to>:<port you are forwarding to>
let me know if this works
|
|
|
08-17-2006, 12:17 AM
|
#5
|
Member
Registered: Apr 2006
Location: Vienna-Austria
Distribution: Suse 10.x, Fedora, DSL
Posts: 63
Rep:
|
I face exactly the same problem !
I want to forward external requests to an internal http-server !
A nice fellow here told me that changing the port is not a good idea for http-requests, because it is stored redundant in the http-header, which is pretty weard in IMHO, but anyway I made sure that the port has not to be translated.
So I used exactly the statment you posted, but it seemd to me, nothing changed ?
I'd like to mention that SNAT and Firewalling works fine on that box......
|
|
|
08-17-2006, 07:53 AM
|
#6
|
Senior Member
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Original Poster
Rep:
|
Well.... the problem could be that the source address of the packets that you are DNATing aren't changed.... and when they reach the server that you wanted to forward them to, when the server wants to reply back, it sends them THROUGH another router that is not the linux box that DNATed the packets... and that's a problem, because they will have a different SOURCE (remember it's the server that's sending them) address of the address that they were intedted to in the first place.
Let's assume the packets were sent from A to B, but B is DNATing to C, C will get packets comming with source address A (if they are not SNATed by B). When he replies back, if instead of sending them to B, it uses another router... say D, packets will reach A with source address C, instead of B.... and that's the problem (at least the one I'm trying to describe). Hope it solves your doubt.
Cheers!
|
|
|
08-22-2006, 01:22 AM
|
#7
|
Member
Registered: Apr 2006
Location: Vienna-Austria
Distribution: Suse 10.x, Fedora, DSL
Posts: 63
Rep:
|
Thanks for the reply, I think I got your point.
So I tried to SNAT these packets back, allthough iptables-doc and some postings here say this should not be required, anyway, I tested it, but it didn't work so far.
Wouldn't this what you are saying not be a general obstacle for DNAT ?
|
|
|
08-22-2006, 03:44 AM
|
#8
|
Member
Registered: Feb 2005
Location: ~h3av3n~
Distribution: RHEL 4, Fedora Core 3,6,7 Centos 5, Ubuntu 7.04
Posts: 227
Rep:
|
What does "route" output on your mailserver?
Did u do this on your mailserver??
Code:
route add default gw <ip address on router/firewall>
and on firewall do this:
Code:
iptables -t nat -A PREROUTING -i <External interface> -d <External interface IP adress> -p tcp --dport 25 -j DNAT --to-destination anotherhost_ip_address:25
iptables -I FORWARD -i <External interface> -o <Internal Interface> -m state --state NEW,ESTABLISHED,RELATED -p tcp --dport 25 -j ACCEPT
Last edited by ~=gr3p=~; 08-22-2006 at 03:55 AM.
|
|
|
08-22-2006, 08:05 AM
|
#9
|
Member
Registered: Apr 2006
Location: Vienna-Austria
Distribution: Suse 10.x, Fedora, DSL
Posts: 63
Rep:
|
Hi ~=gr3p=~ , thanks for response, the problem actually relies to port 80 (http) and not to smtp, but I suppose your advice is valid for
that as well?
|
|
|
08-23-2006, 02:21 AM
|
#10
|
Member
Registered: Apr 2006
Location: Vienna-Austria
Distribution: Suse 10.x, Fedora, DSL
Posts: 63
Rep:
|
Hi, I followed your suggestion and did:
iptables -t nat -A PREROUTING -d <External interface IP adress> -p tcp --dport 8888 -j DNAT --to-destination anotherhost_ip_address:8888
iptables -I FORWARD -m state --state NEW,ESTABLISHED,RELATED -p tcp --dport 8888 -j ACCEPT
I omitted -o and -i option, because I want the DNAT also from internal Lan.
All other iptables rules deleted, but IP_forwarding activated.....
Unfortunately no success !
|
|
|
08-23-2006, 10:34 AM
|
#11
|
Senior Member
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Original Poster
Rep:
|
This kind of problems can get a bit tricky.
You have to get a number of things done.
Let's suppose (cause I haven't read the whole deal) that you want your "routing" host to appear like it's listening on port X and it will forward packets to an inner host address y.y.y.y on port Y. ok?
On the routing host you would need to have to do something like:
Code:
echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -d router's_public_ip -p tcp --dport X -j DNAT --to-destination y.y.y.y:Y
iptables -A FORWARD -d y.y.y.y -p tcp --dport Y -j ACCEPT
iptables -t nat -A POSTROUTING -d y.y.y.y -p tcp --dport Y -j SNAT router's_inner_IP
The last rule is not necessary if the router is the inner server's (the real one) router when the packets are traveling back.
Always that you be testing if it works remember to sniff on both hosts: the router (traffic reaching the server and traffic being forwarded to the server) and the server.... and check itables counters to see if the rules are being applied.... in my experience, it doesn't fail.
Last edited by eantoranz; 08-23-2006 at 10:35 AM.
|
|
|
08-25-2006, 12:44 PM
|
#12
|
Member
Registered: Apr 2006
Location: Vienna-Austria
Distribution: Suse 10.x, Fedora, DSL
Posts: 63
Rep:
|
Hello eonteranz !
Thanks a lot, it workes out now !
I used the two first statments you recommended, as the gateway is the internal default gateway !
Some postings said ( and I repeated this) that changing the port to from xxxx to 80 is not possible for http-servers, because port-number is written in http-header too. THIS IS WRONG !! I tried to change it from port 8888 to 80, and it worked out perfectly !!
So again: Thanks, you helped me very much !!
|
|
|
08-25-2006, 01:11 PM
|
#13
|
Senior Member
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Original Poster
Rep:
|
Cheers 2 that!
|
|
|
All times are GMT -5. The time now is 09:15 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|