-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirewall2.sh
More file actions
executable file
·86 lines (71 loc) · 2.38 KB
/
firewall2.sh
File metadata and controls
executable file
·86 lines (71 loc) · 2.38 KB
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
#!/bin/bash
#
# Firewall Rules
#
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
#
# Accept Established ssh & telnet.
iptables -A INPUT -p tcp --dport ssh -j ACCEPT
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -p tcp --dport telnet -j ACCEPT
#
# Allow http & https
iptables -A INPUT -p tcp --dport 80 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT
#
# Allow ftp
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
#
# Allow webmin & cockpit & 5081
iptables -A INPUT -p tcp --dport 10000 -j ACCEPT
iptables -A INPUT -p tcp --dport 9090 -j ACCEPT
iptables -A INPUT -p tcp --dport 5081 -j ACCEPT
#
# Accept only 1 ping per second. Faster than that gets dropped & logged.
iptables -A INPUT -p icmp -m icmp --icmp-type echo-request -m limit --limit 1/second -j ACCEPT
iptables -A INPUT -p icmp -m icmp --icmp-type echo-request -j LOG
iptables -A INPUT -p icmp -m icmp --icmp-type echo-request -j DROP
#
# Allow ongoing & local connections
iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -s 127.0.0.1 -j ACCEPT
#
# Accept MySQL
#iptables -A INPUT -p tcp --dport 3306 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
#
# Allow all outgoing
iptables -A OUTPUT -m state --state NEW,ESTABLISHED -j ACCEPT
#
# Loopbacks
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
#
#DOCKER
iptables -N DOCKER
iptables -N DOCKER-ISOLATION
iptables -N DOCKER-USER
iptables -A FORWARD -j DOCKER-USER
iptables -A FORWARD -j DOCKER-ISOLATION
iptables -A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -o docker0 -j DOCKER
iptables -A FORWARD -i docker0 ! -o docker0 -j ACCEPT
iptables -A FORWARD -i docker0 -o docker0 -j ACCEPT
iptables -A DOCKER-ISOLATION -j RETURN
iptables -A DOCKER-USER -j RETURN
#
# Reject anything that is not established and passes at forward chain.
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -j REJECT
# Allow anything outgoing.
iptables -A OUTPUT -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
# Reject everything else
iptables -A INPUT -j DROP
#
# Policies
iptables -P INPUT ACCEPT
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
#
# Save rules
iptables-save