Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 03-24-2008, 02:32 AM   #1
Registered: Apr 2005
Distribution: Debian, OpenBSD,Fedora,RedHat
Posts: 228
Blog Entries: 1

Rep: Reputation: 31
iptables-save, iptables-restore, how to set up them in some script

Hi all,

I was curious, regarding download and upload I made on monthly basis so I set up some small but functional download counter like this :

iptables -N download
iptables -N upload

iptables -A INPUT -i eth1 -m state --state RELATED,ESTABLISHED -j download
iptables -A OUTPUT -o eth1 -j upload
....some other rules...

and it works, precisly count how much MB I download.
Using iptables-save -c > state_download.txt I can save it and
iptables-restore -c < state_download.txt restore it.
But here I am in some kind of loop, how to set up the last two steps automaticaly be done during shutdown/start-up process ?

For start-up process it is easy ...update-rc.d and so on, but how when machine is shutdown to save current state of iptables counters in some file and after starting it again, to start count from values writen in previous session.
Thanks in advance

Old 03-24-2008, 11:39 PM   #2
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209

Rep: Reputation: 36
The exact specifics will depend on your distro, but in general, you want to make a script (or edit an existing one) that's run at run level 6 (which is the shutdown run level). For Fedora (which calls the same as at startup, just with a 'stop' argument), you could edit the /etc/rc.d/rc6.d/K74iptables script to add your save command into the 'stop' procedure (K74iptables is just a symlink to /etc/init.d/iptables). Have a look to see how your particular distro shuts itself down. It'll be something similar to what I've described.

Good luck


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Iptables-restore +script error: bad argument COMMIT xorl Linux - Server 5 04-14-2016 03:51 PM
How to restore iptables starting script satimis Ubuntu 2 12-01-2007 05:03 AM
Persistent iptables? Where to save the script? GbyteSupport Linux - Networking 1 12-13-2004 12:41 PM
startup script to set up iptables rules doesn't run alexfittyfives Debian 2 06-01-2004 07:21 PM
How to set iptables script for lan matthewchin Linux - Networking 4 07-21-2003 04:23 AM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:52 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration