All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damian Gatabria <damian_g@speedy.com.ar>
To: netfilter@lists.netfilter.org
Subject: RE: iptables dnat to loopback
Date: Sun, 08 Aug 2004 03:17:58 -0300	[thread overview]
Message-ID: <1091945878.12669.0.camel@localhost> (raw)
In-Reply-To: <D5C9032B2B09C64EA2409D6214E91AC905124D@asimail2.alphanumeric.com>

> >
> > iptables -A PREROUTING -t nat -p tcp -s (client address) --dport \
> > 3306 -j REDIRECT --to-ports 3306
> >
> > I sit in the client box and `telnet (server ip address) 3306`
> > and just get a "connection refused".
> >
> > Am i missing something? Is the rule ok? I have also tried
> > removing the "--to-ports" option to leave the port unchanged,
> > but the result is the same.
> 
> yes--my post was misleading.  REDIRECT does not precisely do what you want.  it rewrites the destination IP address of the packet to be the primary IP of the interface the packet is received on.  i just verfied this by poking through "/usr/src/linux/net/ipv4/netfilter/ipt_REDIRECT.c"--somewhere around line 85, you'll see: 
> 
>                 /* Grab first address on interface. */
>                 newdst = indev->ifa_list->ifa_local;
> 
> which will not get the packet to 127.0.0.1.
> 
> however, after some further testing--your original DNAT *should* work--the problem is probably somewhere in your filter rules.  i just tested this with a machine that has sendmail bound only to 127.0.0.1:
> 
> # netstat -lnt | grep 25
> tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN
> 
> #iptables -t nat -I PREROUTING -i eth0 -p tcp -d 172.30.30.2 --dport 25 -j DNAT --to 127.0.0.1:25
> 
> the log entry associated with the incoming, DNAT-ed packet may not look exactly as you suspect; however.  this is what popped into my logs upon a successful "telnet 172.30.30.2 25" (the packet is received in the INPUT chain, btw):
> 
> Aug  6 13:06:33 fw kernel: IN=lo OUT= MAC=00:00:00:00:00:00:00:00:00:00:00:00:08:00 SRC=127.0.0.1 DST=127.0.0.1 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=21041 DF PROTO=TCP SPT=35801 DPT=25 WINDOW=32767 RES=0x00 SYN URGP=0
> 
> note the inbound interface is "lo" and both the src and dst IP's are 127.0.0.1.  if you need to filter this kind of connection--make sure you specify a "-s x.x.x.x" in your DNAT rule.
> 
> sorry about my earlier post... hope *this* one helps...
> -j



:o( no luck. 
I even tried -F ing INPUT, FORWARD, OUTPUT, PREROUTING and POSTROUTING
before adding the rule, (all policies set to ACCEPT) and still no luck!

Forwarding is enabled, 

net.ipv4.conf.all.forwarding = 1
net.ipv4.ip_forward = 1

and still the packets are going nowhere... however giving 
the loopback an alias with an ip address of, say, 200.136.136.136
works... so why can't I route to 127.0.0.x? Is there anything
else I should check/add?

Thanks for your patience.




-- 
Damian Gatabria <damian_g@speedy.com.ar>



  parent reply	other threads:[~2004-08-08  6:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-06 17:13 iptables dnat to loopback Jason Opperisano
2004-08-07 10:15 ` David Cannings
2004-08-08  6:17 ` Damian Gatabria [this message]
2004-08-08  8:41   ` David Cannings
2004-08-08 17:50     ` Alistair Tonner
2004-08-09 14:40       ` Damian Gatabria
2004-08-10  1:29         ` Damian Gatabria
  -- strict thread matches above, loose matches on Subject: below --
2004-08-06 12:48 Jason Opperisano
2004-08-06 11:38 Damian Gatabria
2004-08-06 11:54 ` Klemen Kecman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1091945878.12669.0.camel@localhost \
    --to=damian_g@speedy.com.ar \
    --cc=netfilter@lists.netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.