Linux Netfilter discussions
 help / color / mirror / Atom feed
From: Bill Hendrickson <wjhendrickson@gmail.com>
To: netfilter list <netfilter@vger.kernel.org>
Subject: Re: SSH Port Forwarding with iptables
Date: Tue, 29 Sep 2009 12:14:15 -0400	[thread overview]
Message-ID: <a0017e7e0909290914v7a4efac0u69f7cfdeaf7bb4e2@mail.gmail.com> (raw)
In-Reply-To: <a0017e7e0909290816i35c5e55dw77ec8517232ef276@mail.gmail.com>

okay, i simplified my script, and tried MASQUERADE vs FORWARD, and got
it to work:

iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 2022 -j DNAT
--to-destination 172.16.0.101:22
iptables -t nat -A POSTROUTING -j MASQUERADE

why does this way work?  what are the ramifications of using
masquerading, i.e., any reason i shouldn't adopt this method?
>
> #!/bin/bash
>
> modprobe iptable_nat
> echo 1 > /proc/sys/net/ipv4/ip_forward
>
> EXT_IFACE="eth0"
> EXT_IP="172.17.17.165"
> INT_IFACE="eth1"
>
> SSH_IP="172.16.0.101"
> SSH_PORT="2203"
>
> IPT="/sbin/iptables"
> $IPT -F
> $IPT -F -t nat
> $IPT -X
>
> $IPT -A OUTPUT -o $EXT_IFACE -m state --state ESTABLISHED,RELATED -j ACCEPT
> $IPT -A OUTPUT -o $INT_IFACE -m state --state ESTABLISHED,RELATED -j ACCEPT
>
> # wide open, for testing...
> $IPT -t nat -P PREROUTING ACCEPT
> $IPT -t nat -P POSTROUTING ACCEPT
> $IPT -t nat -P OUTPUT ACCEPT
>
> $IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
> $IPT -A INPUT -i lo -j ACCEPT
>
> $IPT -t nat -A PREROUTING -p tcp -i $EXT_IFACE -d $EXT_IP --dport
> $SSH_PORT --sport 1024:65535 -j DNAT --to $SSH_HOST:22
> $IPT -A FORWARD -p tcp -i $EXT_IFACE -o $INT_IFACE -d $SSH_HOST
> --dport $SSH_PORT --sport 1024:65535 -m state --state NEW -j ACCEPT
>
> $IPT -A FORWARD -j LOG --log-prefix "meh "
>

  reply	other threads:[~2009-09-29 16:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-29 15:16 SSH Port Forwarding with iptables Bill Hendrickson
2009-09-29 16:14 ` Bill Hendrickson [this message]
2009-10-01 10:37   ` Pascal Hambourg
2009-10-01 15:24     ` Bill Hendrickson
2009-10-01 22:07       ` Pascal Hambourg
2009-10-01 16:26     ` Gáspár Lajos
2009-09-29 16:16 ` Gáspár Lajos
2009-09-29 16:41   ` Bill Hendrickson
2009-09-29 17:00     ` Gáspár Lajos
2009-09-29 17:12       ` Bill Hendrickson

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=a0017e7e0909290914v7a4efac0u69f7cfdeaf7bb4e2@mail.gmail.com \
    --to=wjhendrickson@gmail.com \
    --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