Owke, simpel netwerkje linuxbakkie met kabelmodem die ook wat servertjes daait (irc, mail, web)die inet moet routen voor het netwerk erachter (192.168.0.0)
rc.firewall
Aangezien dit script voor iemand anders is en ik het hier niet kan testen zou ik willen vragen of iemand hier wat fouten in ziet...
rc.firewall
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
| #!/bin/bash
#Firewall and NAT/MASQ scrippie versie 0.0alpha
#waar hebben we iptables verstopt?
iptables="/usr/sbin/iptables"
#nice line
echo "*** ***"
#Interne netwerk interface
int_iface="eth0"
int_netw="192.168.0.0/24"
int_addr="192.168.0.3/24"
universe=".0.0/0"
echo "*** Internal interface: $int_iface ***"
echo "*** Internal address: $int_addr ***"
echo "*** Internal network: $int_netw ***"
#Externe (internet) interface
ext_iface="eth1"
ext_addr=`/sbin/ifconfig $ext_iface|grep 'inet addr'|awk '{print $2}'|sed -e 's/.*://'`
echo "*** External interface: $ext_iface ***"
echo "*** External address: $ext_addr ***"
#nice line
echo "*** ***"
echo "*** Loading modules: ***"
/sbin/modprobe ip_tables
echo "*** Loading module: ip_tables ***"
/sbin/modprobe ip_conntrack
echo "*** Loading module: ip_conntrack ***"
/sbin/modprobe ip_conntrack_ftp
echo "*** Loading module: ip_conntrack_ftp ***"
/sbin/modprobe ip_conntrack_irc
echo "*** Loading module: ip_conntrack_irc ***"
/sbin/modprobe iptable_nat
echo "*** Loading module: iptable_nat ***"
echo "*** Done ***"
#nice line
echo "*** ***"
#enable ipv4 forwarding
echo "*** Enabling ipv4 Forwarding ***"
echo "1">/proc/sys/net/ipv4/ip_forward
#enable dynamic address
echo "*** Enabling ipv4 Dynaddr ***"
echo "1">/proc/sys/net/ipv4/ip_dynaddr
#nice line
echo "*** ***"
#Setting IP forwarding & Masq
echo "*** Setting default policies ***"
echo "*** Input: DROP ***"
echo "*** Output: DROP ***"
echo "*** Forward: DROP ***"
$iptables -P INPUT DROP
$iptables -F INPUT
$iptables -P OUTPUT DROP
$iptables -F INPUT
$iptables -P FORWARD DROP
$iptables -F INPUT
$iptables -F -t nat
#nice line
echo "*** ***"
echo "*** Deleting existing chains ***"
$iptables -X
#nice line
echo "*** ***"
echo "*** Resetting counters ***"
$iptables -Z
#nice line
echo "*** ***"
echo "*** Creating DROP chain ***"
#log alles wat binnenkomt en rejecten
$iptables -N drop-and-log-it
$iptables -A drop-and-log-it -j LOG --log-level info
$iptables -A drop-and-log-it -j REJECT
#nice line
echo "*** ***"
echo "*** Loading INPUT rulesets ***"
#loopback interface mag alles inputten
$iptables -A INPUT -i lo -s $universe -d $universe -j ACCEPT
#lokale interface, lokaal netwerk, overal heen valid
$iptables -A INPUT -i $int_iface -s $int_netw -d $universe -j ACCEPT
#externe interface, lokaal netwerk, overal heen sturen naar drop-and-log-it chain
$iptables -A INPUT -i $ext_iface -s $int_netw -d $universe -j drop-and-log-it
#externe interface, van ieder addres, naar ext_ip, ICMP packet, valid
$iptables -A INPUT -i $ext_iface -p ICMP -s $universe -d $ext_addr -j ACCEPT
#MASQ verkeer moet er weer inkunnen
$iptables -A INPUT -i $ext_iface -s $universe -d $ext_addr -m state --state ESTABLISHED,RELATED -j ACCEPT
#poort 80 22 6667 en 110 openzetten voor ext iface
echo "*** Allowing trafic on port 80 ***"
#www
$iptables -A INPUT -i $ext_iface -s $universe -d $ext_addr -p tcp --dport 80 -j ACCEPT
$iptables -A INPUT -i $ext_iface -s $universe -d $ext_addr -p udp --dport 80 -j ACCEPT
echo "*** Allowing trafic on port 22 ***"
#SSH
$iptables -A INPUT -i $ext_iface -s $universe -d $ext_addr -p tcp --dport 22 -j ACCEPT
echo "*** Allowing trafic on port 6667 ***"
#IRC
$iptables -A INPUT -i $ext_iface -s $universe -d $ext_addr -p tcp --dport 6667 -j ACCEPT
$iptables -A INPUT -i $ext_iface -s $universe -d $ext_addr -p udp --dport 6667 -j ACCEPT
echo "*** Allowing trafic on port 110 ***"
#Mail
$iptables -A INPUT -i $ext_iface -s $universe -d $ext_addr -p tcp --dport 110 -j ACCEPT
#Regeltje die alles wat niet matched logged en reject
$iptables -A INPUT -i $ext_iface -s $universe -d $universe -j drop-and-log-it
echo "*** Done ***"
#nice line
echo "*** ***"
echo "*** Loading OUTPUT rulesets ***"
#loopback iface mag uiteraard
$iptables -A OUTPUT -o lo -s $universe -d $universe -j ACCEPT
#naar interne interface van externe iface, naar lokaalnet (das wel makkelijk :))
$iptables -A OUTPUT -o $int_iface -s $ext_addr -d $int_netw -j ACCEPT
#van interne interface naar interne interface, naar lokaalnet
$iptables -A OUTPUT -o $int_iface -s $int_addr -d $int_netw -j ACCEPT
#Externe interface, naar lokaalnet das niet goe
$iptables -A OUTPUT -o $ext_iface -s $universe -d $int_netw -j drop-and-log-it
#Externe interface mag alles verzenden (niet met lokaal doeladress, zie boven) en alleen met ons ext_ipaddress als source
$iptables -A OUTPUT -o $ext_iface -s $ext_addr -d $universe -j ACCEPT
#Regeltje die de rest trashed (dus niet met ons externe ip al source
$iptables -A OUTPUT -o $ext_iface -s $universe -d $universe -j drop-and-log-it
echo "*** Done ***"
#nice line
echo "*** ***"
echo "*** Loading FORWARD (MASQ)rulesets ***"
#alleen bestaande connecties naar binnen toe
$iptables -A FORWARD -i $ext_iface -o $int_iface -m state --state ESTABLISHED,RELATED -j ACCEPT
#van interne iface naar de externe toe
$iptables -A FORWARD -i $int_iface -o $ext_iface -j ACCEPT
#de rest trashen en loggen
$iptables -A FORWARD -j drop-and-log-it
echo "*** Done ***"
#nice line
echo "*** ***"
echo "***+++--- Vuurmuur gestart ---+++***" |
Aangezien dit script voor iemand anders is en ik het hier niet kan testen zou ik willen vragen of iemand hier wat fouten in ziet...