rc.local
Here is my rc.local file:
#!/bin/bash
#
# This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
IPT="/sbin/iptables"
$IPT -F
$IPT -Z
if [ ! -r x ]; then
# No value from previous run - initialize x
x=1
else
x=$((cat x))
echo "Value of x from previous run = $x"
fi
if [ $x -eq 1 ]; then
#FW1 IP: 192.168.10.2
$IPT -A FORWARD -i eth0 -o eth0 -s 192.168.10.0/24 -d
192.168.10.0/24 -p icmp --icmp-type echo-request -j ACCEPT
$IPT -A FORWARD -i eth0 -o eth0 -s 192.168.10.0/24 -d
192.168.10.0/24 -p icmp --icmp-type echo-reply -j ACCEPT
x=0;
else
#FW2 IP: 192.168.10.3
$IPT -A FORWARD -i eth0 -o eth1 -s 192.168.10.0/24 -d
192.168.10.0/24 -p icmp --icmp-type echo-request -j ACCEPT
$IPT -A FORWARD -i eth0 -o eth1 -s 192.168.10.0/24 -d
192.168.10.0/24 -p icmp --icmp-type echo-reply -j ACCEPT
x=1;
fi
# Save variable to file
echo $x >x
executing a firewall script!!
In reply to a message not in the archiveHi to all,
I would like to know how to execute a firewall script that contains an if-else statement on a per-packet basis. The if and else part each contain iptables rules that need to be executed on a packet basis? How can I do that?
Any input will be most appreciated..
Warm regards,
Visham
Re: executing a firewall script!!
Quoted 8 lines · Visham Ramsurrun
Hi to all,
I would like to know how to execute a firewall script that contains an if-else statement on a per-packet basis. The if and else part each contain iptables rules that need to be executed on a packet basis? How can I do that?
Any input will be most appreciated..
First guess is with two chains.. it's clear you have a test for the 'if (test) then X' sequence, so write a rule to check that test. Instead of REJECTing or ACCEPTing the packet immediately, send it over to different chain for additional testing, and ACCEPT or REJECT it there.
Does that make sense?
Perhaps a more detailed explaination of what you're trying to do would be helpful...
HTH...
- --
"There are 10 types of people in the world: Those who understand binary and those that don't."
Re: executing a firewall script!!
In reply to a message not in the archiveQuoted 21 lines · Visham Ramsurrun
Dear Carl,
many thx for the reply...i too thought abt that..but i don't know how to do it. Here is my firewall script.
#!/bin/bash
IPT="/sbin/iptables"
$IPT -F
$IPT -Zif [ ! -r x ]; then
# No value from previous run - initialize x
x=1
else
x=$((cat x))
echo "Value of x from previous run = $x"
fi
Quoted 15 lines
if [ $x -eq 1 ]; then
#FW1 IP: 192.168.10.2
$IPT -A FORWARD -i eth0 -o eth0 -s 192.168.10.0/24 -d
192.168.10.0/24 -p icmp --icmp-type echo-request -j ACCEPT
$IPT -A FORWARD -i eth0 -o eth0 -s 192.168.10.0/24 -d
192.168.10.0/24 -p icmp --icmp-type echo-reply -j ACCEPT
x=0;
else
#FW2 IP: 192.168.10.3
$IPT -A FORWARD -i eth0 -o eth1 -s 192.168.10.0/24 -d
192.168.10.0/24 -p icmp --icmp-type echo-request -j ACCEPT
$IPT -A FORWARD -i eth0 -o eth1 -s 192.168.10.0/24 -d
192.168.10.0/24 -p icmp --icmp-type echo-reply -j ACCEPT
x=1;
fi
So you want FW1 to reply to allow every other ping, and FW2 to allow those that FW1 ignores?
I'm sure there's a way, but I'm certainly not the authority on load balancing. Others here I'm sure are more adept at fielding this sort of question.
HTH.
Carl
- --
"There are 10 types of people in the world: Those who understand binary and those that don't."
Quoted 1 line · Visham Ramsurrun
Here is my rc.local file:
[snip]
I think this is a shell scripting problem, not an iptables problem. You seem to be forwarding pings to different interfaces per script invocation (usually during boot time)? What are you trying to accomplish? If you state your goal, the list might be able to come up with a solution using iptables.
Other things:
Usually if you accept pings in one direction (say -i eth0 -o eth1) you want pongs to go in the other direction (-i eth1 -o eth0).
I'm not exactly sure why you are forwarding from an interface to itself, though I don't have much experience with this kind of thing.
Quoted 3 lines · Visham Ramsurrun
you are right..i'm having a scripting problem..i don't know how to make a script execute every time a packet is sent by my PC. how can i do that?
You don't want to execute a script for each packet... you could be easily DoSed. Try:
http://netfilter.org/patch-o-matic/pom-base.html#pom-base-nth
Please reply to the list, so everyone can help and learn. =)
Quoted 5 lines · curby .
Quoted 3 lines · Visham Ramsurrun
you are right..i'm having a scripting problem..i don't know how to make a script execute every time a packet is sent by my PC. how can i do that?
Quoted 7 lines
You don't want to execute a script for each packet... you could be easily DoSed. Try:
http://netfilter.org/patch-o-matic/pom-base.html#pom-base-nth
Please reply to the list, so everyone can help and learn. =)
No I only want to execute a script for all packets that are packets that are going to be sent out of the NIC (after the packets have been accepted as valid by a firewall). I don't know how to do that. Do you know what is the last function in the iptables code or the first function in the NIC driver, that a packet that has been accepted by the firewall passes before it is sent on the wire? I would then write some code so that when a call is made to that function, a signal is raised and it will cause a shell script to execute.
I don't know abt the DoSed command. Do you have any example?
If there is an easier way, please let me know...
MAny thx for the reply.
Warm regards,
Visham
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
you are right..i'm having a scripting problem..i don't know how to make a script execute every time a packet is sent by my PC. how can i do that?
Quoted 8 lines
Quoted 5 lines
You don't want to execute a script for each packet... you could be easily DoSed. Try:
http://netfilter.org/patch-o-matic/pom-base.html#pom-base-nth
Please reply to the list, so everyone can help and learn. =)No I only want to execute a script for all packets that are packets that are going to be sent out of the NIC (after the packets have been
That's still a DOS. If I pingflood you, your machine will most likely respond with "pongflood".
I have iptraf running for like 4 or 5 days now and it shows almost 11 GB which approximates to ~ 34 KB/sec (inet radio ;). Let's assume that every packet was 1500 bytes long - then this would mean that I would be starting 23 processes per second, which really is inefficient.
And, you're looking for -j QUEUE.
Quoted 8 lines
accepted as valid by a firewall). I don't know how to do that. Do you know what is the last function in the iptables code or the first function in the NIC driver, that a packet that has been accepted by the firewall passes before it is sent on the wire? I would then write some code so that when a call is made to that function, a signal is raised and it will cause a shell script to execute.
I don't know abt the DoSed command. Do you have any example?
Quoted 8 lines
If there is an easier way, please let me know...
MAny thx for the reply.
Warm regards,
Visham
Jan Engelhardt
Signature · 1 line
| Alphagate Systems, http://alphagate.hopto.org/
I am running the same script for all the packets. After it finishes execution, it waits for the next signal (i.e the next packet to pass)
Regards,
Visham
Quoted 44 lines · Jan Engelhardt
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
you are right..i'm having a scripting problem..i don't know how to make a script execute every time a packet is sent by my PC. how can i do that?
Quoted 8 lines
Quoted 5 lines
You don't want to execute a script for each packet... you could be easily DoSed. Try:
http://netfilter.org/patch-o-matic/pom-base.html#pom-base-nth
Please reply to the list, so everyone can help and learn. =)No I only want to execute a script for all packets that are packets that are going to be sent out of the NIC (after the packets have been
That's still a DOS. If I pingflood you, your machine will most likely respond with "pongflood".
I have iptraf running for like 4 or 5 days now and it shows almost 11 GB which approximates to ~ 34 KB/sec (inet radio ;). Let's assume that every packet was 1500 bytes long - then this would mean that I would be starting 23 processes per second, which really is inefficient.
And, you're looking for -j QUEUE.
Quoted 8 lines
accepted as valid by a firewall). I don't know how to do that. Do you know what is the last function in the iptables code or the first function in the NIC driver, that a packet that has been accepted by the firewall passes before it is sent on the wire? I would then write some code so that when a call is made to that function, a signal is raised and it will cause a shell script to execute.
I don't know abt the DoSed command. Do you have any example?Quoted 8 lines
If there is an easier way, please let me know...
MAny thx for the reply.
Warm regards,
VishamJan Engelhardt
--
| Alphagate Systems, http://alphagate.hopto.org/
Sorry got confused with the DoSed and the sed shell command..i want to execute the same script for each packet. After execution, it wits for the next signal (i.e another valid packet that is passing by before going on the wire) to execute again.
Pls help me..
Regards,
Visham
Hi Rob,
i took note of the different propositions for iptables. I actually don't have these facilities in ebtables. I want to find the iptables function that will be analogous to the one in ebtables.The script is very small. I think i can afford the overhead.
Regards,
Visham
Quoted 2 lines
Sorry got confused with the DoSed and the sed shell command..i want to execute the same script for each packet.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You mean to have the same shell _process_ analyze each packet.. Check the QUEUE target.
Jan Engelhardt
Signature · 1 line
| Alphagate Systems, http://alphagate.hopto.org/