1 |
On Mon, 2010-04-05 at 19:32 +0200, Jarry wrote: |
2 |
> Hi |
3 |
> |
4 |
> I'd like to ask if there is some way to include multiple discrete |
5 |
> hosts/IP's in --source and --destination options of iptables. |
6 |
> |
7 |
> I'm trying to write firewall rules for my server, but it has |
8 |
> 12 IP's from different segments (and maybe it gets a few more |
9 |
> later), and the script grows up as I have to write nearly |
10 |
> identical rules with difference only in -s/-d IP's. |
11 |
> |
12 |
> What I'm looking for is a way to define some variable at the |
13 |
> beginning of my script, like MY_IP="IP1 IP2 IP3 IP4..." and |
14 |
> later to use is in rules (iptables -A INPUT -s $MY_IP...). |
15 |
> But I do not know how to use it. As far as I understand it, |
16 |
> --source/--destination accepts only single IP's or continuous |
17 |
> IP-segments... |
18 |
|
19 |
You can do something like: |
20 |
(100) iptables -N IP_SET_CHECK |
21 |
(110) iptables -A IP_SET_CHECK -s $IP1 -j RETURN |
22 |
(120) iptables -A IP_SET_CHECK -s $IP2 -j RETURN |
23 |
(130) iptables -A IP_SET_CHECK -s $IP3/16 -j RETURN |
24 |
(140) iptables -A IP_SET_CHECK -s $IP4 -j RETURN |
25 |
(150) iptables -A IP_SET_CHECK -j DROP |
26 |
|
27 |
(210) iptables -A INPUT -j IP_SET_CHECK |
28 |
(220) iptables -A INPUT some other rules.... |
29 |
(230) iptables -A INPUT some other rules.... |
30 |
|
31 |
So, when it comes to the the line 210, it will start checking newly |
32 |
created chain IP_SET_CHECK. If it won't find appropriate rule it will be |
33 |
dropped at the line (150), but if manages to find one, it will return to |
34 |
the line 220 and will continue looking for "-j ACCEPT" or "-j DROP". |
35 |
|
36 |
The same applies for the OUTPUT chain. |
37 |
|
38 |
> Jarry |
39 |
> |