From: Matt Killock <lists@killock.net>
To: "Neal P. Murphy" <neal.p.murphy@alum.wpi.edu>
Cc: netfilter@vger.kernel.org, netfilter-owner@vger.kernel.org
Subject: Re: Iptables Reject with TCP Reset
Date: Tue, 10 Jan 2017 19:29:40 +0000 [thread overview]
Message-ID: <97e9b02ea87a5c04a31f5be7ab26f2ff@killock.net> (raw)
In-Reply-To: <20170110133221.560d3b6d@playground>
> This doesn't make much sense. A RELATED packet is the first packet of
> a new conn that a helper has determined is related to an existing conn
> (e.g., the data conn of an FTP control session). Once a RELATED packet
> is replied to, the resulting conn is an ordinary, vanilla ESTABLISHED
> conn; specifically, the RELATED 'tag' is discarded. When a packet
> matches a "REJECT with TCP-Reset" rule, netfilter immediately sends a
> TCP RESET to the end that sent the packet.
Sounds nice in theory, but reality bites back. RELATED also applies to
the TCP Reset packets to SYN packets.
I just tried this at home to confirm my findings.
Please review the below firewall script. It does not send the TCP RST
packets unless you make one minor change: To add 'RELATED,' to the line
underneath '#General State Matching'
Please note that it has the single state matching lines as recommended
by various others on this list.
> It almost sounds like you built a nearly stateless firewall.
It's more or less like the below but duplicates ESTABLISHED everywhere
------------------------------
A='/sbin/iptables'
EXIF='ppp0'
LANIF='eth1'
#Clear
$A -F
$A -F INPUT
$A -F OUTPUT
$A -F FORWARD
$A -F -t mangle
$A -F -t nat
$A -X
#Setup policies
$A -P INPUT DROP
$A -P OUTPUT DROP
$A -P FORWARD DROP
echo "1" > /proc/sys/net/ipv4/ip_forward
# Some basics
# Accept loopback interface
$A -A INPUT -i lo -j ACCEPT
A='/sbin/iptables'
EXIF='ppp0'
LANIF='eth1'
#Clear
$A -F
$A -F INPUT
$A -F OUTPUT
$A -F FORWARD
$A -F -t mangle
$A -F -t nat
$A -X
#Setup policies
$A -P INPUT DROP
$A -P OUTPUT DROP
$A -P FORWARD DROP
echo "1" > /proc/sys/net/ipv4/ip_forward
# Some basics
# Accept loopback interface
$A -A INPUT -i lo -j ACCEPT
$A -A OUTPUT -o lo -j ACCEPT
# SSH from LAN
$A -A INPUT -i $LANIF -p tcp --dport 22 -j ACCEPT
#general NAT
$A -t nat -A POSTROUTING -o $EXIF -j MASQUERADE
#General State Matching
$A -A OUTPUT -m state --state ESTABLISHED -j ACCEPT
$A -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
#Allowed HTTP/HTTPS Sites
#bbc
$A -A FORWARD -i $LANIF -o $EXIF -d 212.58.244.22 -p tcp -m multiport
--dports '80,443' -j ACCEPT
#Send RST to LAN for all other 80/443 connections
$A -A FORWARD -i $LANIF -p tcp -m multiport --dports '80,443' -j REJECT
--reject-with tcp-reset
--------------------
Matt
next prev parent reply other threads:[~2017-01-10 19:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-06 15:19 Iptables Reject with TCP Reset Matt Killock
2017-01-06 16:09 ` Noel Kuntze
2017-01-06 16:28 ` Matt Killock
2017-01-06 16:35 ` Noel Kuntze
[not found] ` <HK2PR0201MB212932A38853DB306E300014E8630@HK2PR0201MB2129.apcprd02.prod.outlook.com>
2017-01-06 17:52 ` Noel Kuntze
2017-01-09 10:45 ` Matt Killock
2017-01-10 7:35 ` André Paulsberg-Csibi (IBM Consultant)
2017-01-10 10:09 ` Matt Killock
2017-01-10 11:41 ` André Paulsberg-Csibi (IBM Consultant)
2017-01-10 18:32 ` Neal P. Murphy
2017-01-10 19:29 ` Matt Killock [this message]
2017-01-11 10:21 ` André Paulsberg-Csibi (IBM Consultant)
2017-01-11 10:34 ` Matt Killock
2017-01-06 17:30 ` Ethy H. Brito
2017-01-06 23:26 ` Neal P. Murphy
2017-01-06 23:40 ` Noel Kuntze
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=97e9b02ea87a5c04a31f5be7ab26f2ff@killock.net \
--to=lists@killock.net \
--cc=neal.p.murphy@alum.wpi.edu \
--cc=netfilter-owner@vger.kernel.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 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.