LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 03-24-2008, 03:32 AM   #1
sarajevo
Member
 
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

Regards
 
Old 03-25-2008, 12:39 AM   #2
beadyallen
Member
 
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
 
  


Reply


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
How to restore iptables starting script satimis Ubuntu 2 12-01-2007 06:03 AM
Iptables-restore +script error: bad argument COMMIT xorl Linux - Server 4 06-24-2007 10:50 AM
Persistent iptables? Where to save the script? GbyteSupport Linux - Networking 1 12-13-2004 01:41 PM
startup script to set up iptables rules doesn't run alexfittyfives Debian 2 06-01-2004 08:21 PM
How to set iptables script for lan matthewchin Linux - Networking 4 07-21-2003 05:23 AM


All times are GMT -5. The time now is 09:46 AM.

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