public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Martin Vaeth <vaeth@mathematik.uni-wuerzburg.de>
To: gentoo-user@lists.gentoo.org
Subject: [gentoo-user] Re: scripted iptables-restore
Date: Sun, 13 Oct 2013 15:19:26 +0000 (UTC)	[thread overview]
Message-ID: <slrnl5leg8.a3q.vaeth@lounge.imp.fu-berlin.de> (raw)
In-Reply-To: 525AAADE.7040700@orlitzky.com

Michael Orlitzky <michael@orlitzky.com> wrote:
> On 10/13/2013 06:08 AM, Martin Vaeth wrote:
>>>> 5. You can't script iptables-restore!
>>>
>>> Well, actually you can script iptables-restore.
>>
>> For those who are interested:
>> net-firewall/firewall-mv from the mv overlay
>> (available over layman) now provides a separate
>> firewall-scripted.sh
>> which can be conveniently used for such scripting.
>>
> [...]
> If you have a million rules and you need to wipe/reload them all
> frequently you're probably doing something wrong to begin with.

I don't know how this is related with the discussion.
The main advantage of using iptables-restore is avoidance of
race conditions. A secondary advantage is a speed improvement;
in my case, the machine boots about 2 seconds faster which can
be a considerable advantage if you start virtual machines.

> With bash [...]

(I would use a POSIX shell because it is considerably faster,
but this need not be discussed here.)

That's why I said that it can be scripted
(which was my motivation to write firewall-scripted.sh):

firewall-scripted.sh (or some similar script) gives you exactly
the same advantages, but without races, and faster.
In your example:

> function static_nat() {
>    iptables -t nat -A PREROUTING  -d "${2}" -j DNAT --to "${1}"
>    iptables -t nat -A POSTROUTING -s "${1}" -j SNAT --to "${2}"
> }

Essentially, you just have to replace "iptables" by "FwmvTables 4".
If you are too lazy to use a text editor or to replace "iptables"
by a variable (like $iptables) you can do this even by
defining the function:

iptables() {
  FwmvTables 4 "${@}"
}

Then you just put in front of your script the line

. firewall-scripted.sh

and in the end (or before you call exit):

FwmvSet 4

That's it...

> I'm not saying you can't do all of this with iptables-restore, just that
> you're punishing yourself for little benefit if you do.

*Using* firewall-scripted.sh is as convenient as using iptables directly
(you just replace one command and add two lines to your script).
Of course, the disadvantage is that some day firewall-scripted.sh might
break with iptables (and that maybe the script still has bugs...).
As I said, it would be better if something similar would be provided
by iptables itself. But the advantages are clear.



  reply	other threads:[~2013-10-13 15:20 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-03 19:27 [gentoo-user] Where to put advanced routing configuration? Grant Edwards
2013-10-03 20:28 ` Kerin Millar
2013-10-04 16:25   ` [gentoo-user] " Grant Edwards
2013-10-04 21:58   ` [gentoo-user] " Michael Orlitzky
2013-10-04 22:33     ` Dragostin Yanev
2013-10-11  7:18     ` [gentoo-user] " Martin Vaeth
2013-10-13 10:08       ` [gentoo-user] scripted iptables-restore (was: Where to put advanced routing configuration?) Martin Vaeth
2013-10-13 14:14         ` [gentoo-user] scripted iptables-restore Michael Orlitzky
2013-10-13 15:19           ` Martin Vaeth [this message]
2013-10-13 16:37             ` [gentoo-user] " Michael Orlitzky
2013-10-13 20:07               ` Martin Vaeth
2013-10-13 21:45                 ` William Kenworthy
2013-10-14 12:08                   ` Martin Vaeth
2013-10-14 13:27                     ` William Kenworthy
2013-10-13 22:02                 ` Michael Orlitzky
2013-10-14 11:49                   ` Martin Vaeth
2013-10-14 14:26                     ` Michael Orlitzky
2013-10-14 18:49                       ` Martin Vaeth
2013-10-14 19:17                         ` Michael Orlitzky
2013-10-14 20:31                           ` Alan McKinnon
2013-10-15  1:06                             ` Michael Orlitzky
2013-10-14 18:23                 ` Tanstaafl
2013-10-14 18:52                   ` Martin Vaeth
2013-10-14 19:40                     ` Tanstaafl
2013-10-14 20:45                   ` Alan McKinnon
2013-10-16 23:21                     ` Walter Dnes
2013-10-17  6:59                       ` Alan McKinnon
2013-10-18  2:30                         ` Walter Dnes
2013-10-18  4:44                           ` Alan McKinnon
2013-10-18 10:23                           ` Tanstaafl
2013-10-18 11:19                             ` Alan McKinnon
2013-10-18 14:05                               ` Tanstaafl
2013-10-18 14:33                                 ` Alan McKinnon
2013-10-14  5:54           ` [gentoo-user] " Pandu Poluan
2013-10-14  5:57         ` [gentoo-user] scripted iptables-restore (was: Where to put advanced routing configuration?) Pandu Poluan
2013-10-14 11:52           ` [gentoo-user] " Martin Vaeth
2013-10-13 10:26     ` [gentoo-user] Where to put advanced routing configuration? shawn wilson
2013-10-13 13:53       ` Michael Orlitzky
2013-10-13 13:57       ` [gentoo-user] " Martin Vaeth
2013-10-05 21:01 ` [gentoo-user] " thegeezer
2013-10-06 16:16 ` [gentoo-user] " Grant Edwards

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=slrnl5leg8.a3q.vaeth@lounge.imp.fu-berlin.de \
    --to=vaeth@mathematik.uni-wuerzburg.de \
    --cc=gentoo-user@lists.gentoo.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