This repository was archived by the owner on Nov 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiptables
executable file
·172 lines (117 loc) · 5.02 KB
/
iptables
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
#!/bin/sh
### BEGIN INIT INFO
# Provides: iptables
# Required-Start: mountkernfs $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Set up iptables rules
### END INIT INFO
iptables=/sbin/iptables
### NETWORKS ###
ReteInterna="192.168.1.0/16"
### IP ROUTER ###
IpRouterPubblico="160.80.101.36"
IpRouterPrivato="192.168.1.1"
### INTERFACCE ROUTER ###
InterfacciaEthInterna="eth0"
InterfacciaEthEsterna="eth1"
### IP SERVER ###
Holly="192.168.1.2"
SwitchAlliedTelesyn="192.168.1.5"
### Ftp ###
#Per attivare il modulo ftp su porte non standard (!=21) aggiungerle separate da una virgola
OpzioniModuloFtp="ports=21"
#Per il forwarding delle porte modificare esclusivamente questa funzione, commentando gli eventuali comandi seguendo l'impostazione delle porte già forwardate.
configuration() {
##### Router #####
#### Servizio ssh #####
$iptables -t nat -A PREROUTING -p tcp -d $IpRouterPubblico --dport 2221 -j DNAT --to-destination $IpRouterPubblico:22
$iptables -t filter -A INPUT -p tcp -d $IpRouterPubblico --dport 22 -j ACCEPT
#######################
##################
##### Holly #####
##### Servizio http #####
$iptables -t nat -A PREROUTING -p tcp -d $IpRouterPubblico --dport 80 -j DNAT --to-destination $Holly:80
$iptables -t filter -A FORWARD -p tcp -d $Holly --dport 80 -j ACCEPT
#########################
##### SCM (Server di versioning) #####
$iptables -t nat -A PREROUTING -p tcp -d $IpRouterPubblico --dport 8080 -j DNAT --to-destination $Holly:8080
$iptables -t filter -A FORWARD -p tcp -d $Holly --dport 8080 -j ACCEPT
######################################
##### Servizio ftp comandi #####
$iptables -t nat -A PREROUTING -p tcp -d $IpRouterPubblico --dport 21 -j DNAT --to-destination $Holly:21
$iptables -t filter -A FORWARD -p tcp -d $Holly --dport 21 -j ACCEPT
# Abilitare il server ftp in modalità passiva. I moduli nf_conntrack_ftp e nf_nat_ftp girano i pacchetti
# sulla macchina giusta e li settano in modalità related
#############################################
##### Servizio ssh #####
$iptables -t nat -A PREROUTING -p tcp -d $IpRouterPubblico --dport 22 -j DNAT --to-destination $Holly:22
$iptables -t filter -A FORWARD -p tcp -d $Holly --dport 22 -j ACCEPT
########################
##### Servizio transmission webUI+comandi #####
$iptables -t nat -A PREROUTING -p tcp -d $IpRouterPubblico --dport 9091 -j DNAT --to-destination $Holly:9091
$iptables -t nat -A PREROUTING -p tcp -d $IpRouterPubblico --dport 34567 -j DNAT --to-destination $Holly:34567
$iptables -t filter -A FORWARD -p tcp -d $Holly --dport 9091 -j ACCEPT
$iptables -t filter -A FORWARD -p tcp -d $Holly --dport 34567 -j ACCEPT
############################################
#################
}
start() {
#modprobe nf_conntrack_ftp $OpzioniModuloFtp
#modprobe nf_nat_ftp
configuration
##### FORWARD #####
##### filter #####
$iptables -t filter -P FORWARD DROP
$iptables -t filter -A FORWARD ! -s $ReteInterna -m state --state ESTABLISHED,RELATED -j ACCEPT
$iptables -t filter -A FORWARD -s $ReteInterna -j ACCEPT
##################
##################
##### INPUT #####
##### filter #####
$iptables -t filter -P INPUT DROP
$iptables -t filter -A INPUT ! -s $ReteInterna -m state --state ESTABLISHED,RELATED -j ACCEPT
$iptables -t filter -A INPUT -s $ReteInterna -j ACCEPT
$iptables -t filter -A INPUT -p icmp -j ACCEPT
##################
#################
##### POSTROUTING #####
##### nat #####
$iptables -t nat -A POSTROUTING -o $InterfacciaEthEsterna -s $ReteInterna -j SNAT --to-source $IpRouterPubblico
$iptables -t nat -A POSTROUTING -o $InterfacciaEthInterna -s $ReteInterna -j SNAT --to-source $IpRouterPrivato
###############
#######################
echo 1 > /proc/sys/net/ipv4/ip_forward
}
stop() {
echo 0 > /proc/sys/net/ipv4/ip_forward
$iptables -t nat -F
$iptables -t filter -F
$iptables -t filter -P FORWARD ACCEPT
$iptables -t filter -P INPUT ACCEPT
#rmmod nf_nat_ftp
#rmmod nf_conntrack_ftp
}
case "$1" in
start)
start
echo "Start OK"
;;
stop)
stop
echo "Stop OK"
;;
restart)
stop
echo "Stop ..."
sleep 2
start
echo "Restart OK"
;;
*)
echo "Usage: iptables {start|stop|restart}" >&2
exit 1
;;
esac
exit 0