LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-19-2015, 10:39 AM   #1
Miati
Member
 
Registered: Dec 2014
Distribution: Linux Mint 17.*
Posts: 326

Rep: Reputation: 106Reputation: 106
Correctly loading iptables


I have a fairly simple iptables script.
I want to load it prior to network connection.

I've put it in /etc/init.d/iptables (+ exec bit set)

However, it seems I need to run update-rc.d on it.

After reading through the man pages of update-rc.d I came up with this command in a attempt to load iptables on run level 2 (which as I understand is the runlevel before the network)

Code:
update-rc.d iptables start 2 .
It gives me this error

Code:
update-rc.d: warning: /etc/init.d/iptables missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
update-rc.d: error: expected runlevel [0-9S] (did you forget "." ?)
As I understand it, lsb info is for services.. since my script has no need to start or stop like a service, do I really need it?
Also, do I really need to run it on every run level? I don't understand the point of "stopping" a script at shutdown that does nothing but define a ruleset.

Last edited by Miati; 02-26-2015 at 09:32 AM.
 
Old 02-22-2015, 03:15 PM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
If you're creating an init script it has to conform to being able to start/stop. In this case start would be loading the rules and stop would be flushing them. I recommend you make use of iptables-restore to restore rules and iptables -F to flush them.

If you're less interested treating your firewall rules as a service then you'll have to load the rules some other way. Crontab has the @reboot alias (see man 5 crontab). You could also modify the interface startup so that it loads the rules after starting up the networking.
 
Old 02-22-2015, 06:04 PM   #3
Miati
Member
 
Registered: Dec 2014
Distribution: Linux Mint 17.*
Posts: 326

Original Poster
Rep: Reputation: 106Reputation: 106
i don't mind doing it another way, my main goal is to load the iptables prior to a network connection.
crontab will run @reboot when it is loaded and I am not sure when it is loaded.

Most likely, this is not a issue, but I would like to do this the "correct" way. As I understand it (for example) placing it in rc.local is not correct, since I believe it loads the network prior to running rc.local commands..
 
Old 02-26-2015, 09:32 AM   #4
Miati
Member
 
Registered: Dec 2014
Distribution: Linux Mint 17.*
Posts: 326

Original Poster
Rep: Reputation: 106Reputation: 106
I decided to figure out and identify how to write a init.d script (learn once, use forever right?)
I mostly used the format from other init.d scripts so I can't say I know exactly what I was doing - but it seems to work.
Is there anything "wrong" about the LSB info below?
In any case, it seems to work like this. It may be of use in the future as a reference.
Code:
#!/bin/bash
### BEGIN INIT INFO
# Provides:          iptables
# Required-Start:    $network $remote_fs $syslog
# Required-Stop:     $network $remote_fs $syslog
# Should-Start:      $portmap
# Should-Stop:       $portmap
# X-Start-Before:    nis
# X-Stop-After:      nis
# Default-Start:     2 
# Default-Stop:      1
# X-Interactive:     false
# Short-Description: Iptable setup
# Description:       Sets iptable rules
#                    
### END INIT INFO

ipt=/sbin/iptables


loadrules() {
My iptable rules
}

removerules() {
$ipt -P INPUT ACCEPT
$ipt -P FORWARD ACCEPT
$ipt -P OUTPUT ACCEPT
$ipt -F
$ipt -X
}

case "$1" in
        start)
                loadrules
                ;;
        stop)
                removerules
                ;;
        *)
                echo "Usage: $0 start|stop" >&2
                exit 3
                ;;
esac
(END)
 
  


Reply



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
Sata not loading correctly Rollo69 Linux - Hardware 8 03-28-2009 12:02 PM
Ens1371 not loading correctly sigma957 Debian 3 12-06-2005 08:16 PM
grub problems.... again.... not loading correctly? kahn Linux - Software 1 09-03-2005 10:34 AM
wireless driver not loading correctly dping Linux - Wireless Networking 1 01-15-2005 06:19 PM
Mouse not loading correctly in Slack 9 kpw86 Linux - General 1 09-24-2003 05:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 07:20 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration