-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwhitelist.bash
43 lines (32 loc) · 1.31 KB
/
whitelist.bash
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
#! /bin/bash
############################
# Author : o_be_one for mcTrophy
# Creation date : 2016-03-30
# Goal : whitelist your server : block everything and allow only ip you want for in or out. Care it will flush all existing iptables rules !
# HowTo : edit the end of the file and start the script
############################
# Flush existing rules
iptables -F
# Set up default DROP rule for eth0
iptables -P OUTPUT DROP
iptables -P INPUT DROP
# Allow existing connections to continue
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow remote ip to contact the server
inip() { # allow remote ip to contact this server
iptables -A INPUT -i eth0 -s $1 -j ACCEPT
}
# Allow this host to connect defined remote ip
outip() { # allow this server to send requests to defined ip
iptables -A OUTPUT -o eth0 -d $1 -j ACCEPT
}
outiprelated() { # allow this server to only answer to requests from defined ips
iptables -A OUTPUT -o eth0 -d $1 -m state --state ESTABLISHED,RELATED -j ACCEPT
}
######
# Define your rules !
######
inip 8.33.12.224 # allow this ip to contact the server
outiprelated 8.33.12.224 # allow the server to answer to the ip (only answer, server couldn't contact ip)
inip 88.182.212.10 # allow this ip to contact the server
outip 88.182.212.10 # allow the server to contact the ip