Friday, November 28, 2008

Celestron 44302 Microscope Linux

Advanced Scripts: A script to handle iptables

And again, we have returned. This time, I will show a script to handle basic functions IPTABLES. The purpose of this script, apart from managing IPTABLES, is to teach its use, since every time we use it, make a translation of what we write what he does iptables, so that gradually we will be staying with us IPTABLES operation.
Although of course, also be used to not having to learn IPTABLES;)

Script:



# / bin / bash # #################
ITB # #######
 
Script version 2.5 # # ######################## Daniel Perella

complete_rule = iptables
part_rule =

_aplicar
function {
echo-e "$ part_rule Apply to $ complete_rule? (s / n)" read a

if [[$ a = "s"]]
Then
complete_rule = $ (echo $ Complete_rule $ part_rule) echo
rule: $ complete_rule
else echo
rule: $ complete_rule

fi} function

assistant # wizard: Run a guided wizard to add a rule


{echo "add or remove standard?"
echo "add Read

ac $ ac

echo "Address: source $ A = "add"]]

Then run

else echo-e "you want to delete this rule? (S / n)? \\ C" read bbb

if [[$ bbb = "s"]]
Then run


else echo "Deleted"
fi fi


else echo "Use the help to see what properties"
echo "is available"
echo "" fi




} function add # add [ INPUT _aplicar
}

function remove # remove [INPUT
} function

reject # reject: Reject the rule applies to packets

{echo "-j REJECT"
part_rule = "-j REJECT"}

_aplicar

function ignore # ignore: Apply the rule to DROP packages
{
echo "-j DROP"
part_rule = "-j DROP"
_aplicar
}

function interface # interface [ethn] Defines the interface for standard
{
echo "-i $ 1"
part_rule = " -i $ 1 "}

_aplicar

function number # number [n]: Sets the standard number (useful to clear)

{echo"-I $ 1 "
part_rule ="-I $ 1 "
_aplicar
}

function source # source [IP or HOST]: Defines the source of the package to the standard
{
echo "-s $ 1"
part_rule = "-s $ 1"
_aplicar
}

function target # target [IP or HOST] defines the fate of pquete of standard
{
echo "-d $ 1"
part_rule = "-d $ 1"
_aplicar
}

function rules # rules: For a list of existing rules
{
echo "standard that is being edited"
complete_rule
echo $ echo "Last hand applied or not the standard" part_rule

echo $ echo "" echo
"
i = $ (whoami)
if [[$ i! = "Root"]]
Then
echo "You are not root, you can not do iptables"

else iptables-n-L


fi} function

new # new: Start make a new rule
{
complete_rule = "iptables"
part_rule = ""
echo "New standard launched"



} function run # run: Apply the standard

{echo "Applying standard: $ complete_rule" $

complete_rule echo "Done"


} function save # save file dump
standards
{echo "Save file rules"
if test-n $ 1
Then
nom = $ 1
else
echo-e "file name) \\ c"
read nom
fi
iptables-save> $ nom
echo "Saved about $ nom"
}

function load # load reads a file standards and applies
{
echo "Load rules IPTABLES"
if test-n $ 1
Then
nom = $ 1
else
echo-e "file name) \\ c"
read nom
fi
cat $ nom run
new
done;
}

function flush # flush [INPUT case $ 1 in

- Direct We can use the "wizard" and when we will gather them ease testing the features loose.

If you have doubts, you know where we are! Lucky




0 comments:

Post a Comment