Linux Netfilter discussions
 help / color / mirror / Atom feed
From: Pascal Hambourg <pascal.mail@plouf.fr.eu.org>
To: netfilter@vger.kernel.org
Subject: Re: NAT for locahost to IP LAN for mail services
Date: Fri, 28 Nov 2008 00:42:15 +0100	[thread overview]
Message-ID: <492F3057.8010007@plouf.fr.eu.org> (raw)
In-Reply-To: <98028b00811271446h56adc55bl91f8ae7f152ca8ca@mail.gmail.com>

Zagato a écrit :
> Hi.... im trying to forward the conecction to mail services like smtp(
> port 25) from one pc to another, im using:
> 
> _mail_services=25,110,143,995,993
> _mailserver=192.168.0.3
> iptables -t mangle -A ftolocal -p tcp -m multiport --destination-ports
> $_mail_services -j MARK --set-mark 1
> iptables -t nat -A ftolocal -p tcp -m multiport --destination-ports
> $_mail_services -j DNAT --to-destination 192.168.0.3
> 
> where ftolocal its a chain name for mangle and nat...
> 
> the ip addres source it's 192.168.0.5 and i want to send localhost
> connections to 192.168.0.3...
> when i use the lines above i can:
> telnet 192.168.0.5 25
> and it works... giving me:
> Trying 192.168.0.5...
> Connected to beta.gps.com.co (192.168.0.5).
> Escape character is '^]'.
> 220 alpha.gps.com.co ESMTP Postfix
> 
> But when i use:
> telnet localhost 25 or telnet 127.0.0.1 25 tha must be equal i get..
> Trying 127.0.0.1...
> and statys there forever.....

The difference may lie in the source address. When you send a packet to 
a local address (127.0.0.0/8, 192.168.0.5) and don't set an explicit 
source address (with -b in telnet), the linux kernel selects the same 
local address for the source address. After matching the DNAT rule, 
packets are rerouted to the network interface through which the new 
destination can be reached instead of the loopback interface. However 
the kernel routing prohibits sending packets with a loopback address to 
a non loopback interface, i.e. outside the host. So packets with source 
address 192.168.0.5 are sent out, but packets with source address 
127.0.0.1 are discarded. An additional SNAT rule wouldn't help here 
because it would take place after the packet has been discarded.


  reply	other threads:[~2008-11-27 23:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <98028b00811271443g51a06f71y14b605b9a8b7638f@mail.gmail.com>
2008-11-27 22:46 ` NAT for locahost to IP LAN for mail services Zagato
2008-11-27 23:42   ` Pascal Hambourg [this message]
2008-11-28  0:27     ` Zagato
2008-11-28 11:23       ` Pascal Hambourg
2008-11-29  4:06         ` Zagato
2008-11-29 10:30           ` Pascal Hambourg
2008-11-29 15:41             ` Zagato

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=492F3057.8010007@plouf.fr.eu.org \
    --to=pascal.mail@plouf.fr.eu.org \
    --cc=netfilter@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox