Linux Netfilter discussions
 help / color / mirror / Atom feed
From: "Lloyd Standish" <lloyd@crnatural.net>
To: Thomas Jacob <jacob@internet24.de>
Cc: netfilter@vger.kernel.org
Subject: Re: still can't route using fwmark
Date: Wed, 22 Apr 2009 09:03:39 -0600	[thread overview]
Message-ID: <op.ussmsdrix1lyi3@localhost> (raw)
In-Reply-To: <1240392933.20822.6.camel@enterprise.ims-firmen.de>

On Wed, 22 Apr 2009 03:35:33 -0600, Thomas Jacob <jacob@internet24.de> wrote:

>>
>> I tightened up the policies and added rules to pass any packets, for new connections or otherwise, to or from eth0 (the LAN), and drop NEW connection packets except those from the local machine and from LAN. :
>>
>> iptables -t filter -P INPUT DROP
>> iptables -t filter -P OUTPUT ACCEPT
>> iptables -t filter -P FORWARD DROP
>>
>> iptables -t mangle -A INPUT -i eth0 -j ACCEPT
>> iptables -t mangle -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
>> iptables -t mangle -A FORWARD -i eth0 -j ACCEPT
>> iptables -t mangle -A FORWARD -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
>
> Do you have the ESTABLISHED stuff also in Output? Otherwise you will
> block direct access to that box (see the packet traversal graph
> again)....

I have the OUTPUT policy set to ACCEPT (I want to accept any packets sent by my local box).   According to my understanding, any packet that does not match an OUTPUT rule would therefore be accepted.  It should not be necessary to have any OUTPUT rule, is that right?

My setup is working for LAN-connected machines access only when I set the INPUT policy to ACCEPT, which is too loose for my taste, even though I am behind my ISP's nat/firewall.  Therefore, it seems that the problem must be in my INPUT chain rules.

I got load-balancing for LAN-connected machines (which are natting to both ppp0 or ppp1) working.  I fixed it to configure any single interface (no load-balancing), or both ppp0 and ppp1 for load-balancing, if both interfaces are up.  I put the script in /etc/ppp/ip-up.d and /etc/ppp/ip-down.d, which allows this to auto-configure the interfaces whenever an interface comes up or goes down.  It works very well.

When there is but a single interface up, then, all the load balancing stuff (MARK, CONNTRACK, etc.) is skipped, and the iptables commands become very simple (just a simple firewall with nat for the LAN).   Only the following commands are used when only one interface is up:

src0=`ip route show dev ppp0 2>/dev/null | head -n1 | cut --delimiter=" " --fields=10`
src1=`ip route show dev ppp1 2>/dev/null | head -n1 | cut --delimiter=" " --fields=10`
gw0=`ip route show dev ppp0 2>/dev/null | head -n1 | cut --delimiter=" " --fields=1`
gw1=`ip route show dev ppp1 2>/dev/null | head -n1 | cut --delimiter=" " --fields=1`

# flush all iptables entries
iptables -t filter -F
iptables -t filter -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -t filter -P INPUT DROP
iptables -t filter -P OUTPUT ACCEPT
iptables -t filter -P FORWARD DROP

iptables -t mangle -A INPUT -i lo -j ACCEPT
iptables -t mangle -A INPUT -i eth0 -j ACCEPT
iptables -t mangle -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t mangle -A FORWARD -i eth0 -j ACCEPT
iptables -t mangle -A FORWARD -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t mangle -A OUTPUT -o eth0 -j ACCEPT
iptables -t mangle -A OUTPUT -o lo -j ACCEPT

if [ "$src0" == "" -o "$src1" == "" ]; then
#	echo a device is not online, setting default gateway and quitting
	ip route del default dev ppp0 2>/dev/null
	ip route del default dev ppp1 2>/dev/null
	if [ "$src0" != "" ]; then
		ip route add default dev ppp0
		iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
	fi
	if [ "$src1" != "" ]; then
		ip route add default dev ppp1
		iptables -t nat -A POSTROUTING -o ppp1 -j MASQUERADE
	fi
	exit
fi


I have studied the iptables flow diagram, it seems to me that my INPUT rules above should allow all traffic to/from a LAN-connected (eth0) machine.  However, I am missing something, since I have to set the INPUT policy to ACCEPT to get connectivity from the LAN.  And I have to set the FORWARD policy to ACCEPT to allow my load-balancing stuff to work!

(When this is all fixed I'll post an article about it on my "Linux Notes" site at http://www.voluntary-simplicity.org/linux.)


  reply	other threads:[~2009-04-22 15:03 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-18  4:40 still can't route using fwmark Lloyd Standish
2009-04-18  8:23 ` Thomas Jacob
2009-04-18 17:12   ` Lloyd Standish
2009-04-18 18:48     ` Thomas Jacob
2009-04-18 19:33       ` Lloyd Standish
2009-04-18 20:58         ` Thomas Jacob
2009-04-18 21:49           ` Lloyd Standish
2009-04-19  9:00             ` Thomas Jacob
2009-04-20  5:56               ` Lloyd Standish
2009-04-20  8:48                 ` Javier Gálvez Guerrero
2009-04-20 11:44                   ` Thomas Jacob
2009-04-20 13:08                     ` Javier Gálvez Guerrero
2009-04-20 13:37                       ` Thomas Jacob
2009-04-20 15:15                         ` Javier Gálvez Guerrero
2009-04-20 18:59                           ` Thomas Jacob
2009-04-22  9:53                             ` Javier Gálvez Guerrero
2009-04-22 10:01                               ` Thomas Jacob
2009-04-20 11:09                 ` Thomas Jacob
2009-04-20 12:25                   ` Brian Austin - Standard Universal
2009-04-20 15:38                   ` Lloyd Standish
2009-04-20 19:26                     ` Thomas Jacob
2009-04-21 19:54                       ` Lloyd Standish
2009-04-22  9:35                         ` Thomas Jacob
2009-04-22 15:03                           ` Lloyd Standish [this message]
2009-04-18 23:14           ` Lloyd Standish

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=op.ussmsdrix1lyi3@localhost \
    --to=lloyd@crnatural.net \
    --cc=jacob@internet24.de \
    --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