Iptables Snippets


Host iptables.rules

     /iptables.rules  
 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
# Generated by iptables-save v1.6.1 on Wed Feb 21 16:51:33 2018
*nat
:PREROUTING ACCEPT [857:167163]
:INPUT ACCEPT [255:34541]
:OUTPUT ACCEPT [4:304]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o wlp2s0 -j MASQUERADE
COMMIT
# Completed on Wed Feb 21 16:51:33 2018
# Generated by iptables-save v1.6.1 on Wed Feb 21 16:51:33 2018
*filter
:INPUT ACCEPT [1655:169731]
:FORWARD ACCEPT [29:1612]
:OUTPUT ACCEPT [33:2744]

# Allows HTTP and HTTPS connections from anywhere (the normal ports for websites)
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT

# Allows all outbound traffic
# You could modify this to only allow certain traffic
-A OUTPUT -j ACCEPT

# Allows SSH connections
# The --dport number is the same as in /etc/ssh/sshd_config
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT

# Allow ping
#  note that blocking other types of icmp packets is considered a bad idea by some
#  remove -m icmp --icmp-type 8 from this line to allow all kinds of icmp:
#  https://security.stackexchange.com/questions/22711
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT

-A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i enp3s0 -o wlp2s0 -j ACCEPT
COMMIT
# Completed on Wed Feb 21 16:51:33 2018

Client iptables.rules

     /iptables.rules  
 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
# Generated by iptables-save v1.6.0 on Wed Feb 21 10:35:52 2018
*filter
:INPUT ACCEPT [5:312]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [7:568]

# Allows HTTP and HTTPS connections from anywhere (the normal ports for websites)
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT

# Allows all outbound traffic
# You could modify this to only allow certain traffic
-A OUTPUT -j ACCEPT

# Allows SSH connections
# The --dport number is the same as in /etc/ssh/sshd_config
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT

# Allow ping
#  note that blocking other types of icmp packets is considered a bad idea by some
#  remove -m icmp --icmp-type 8 from this line to allow all kinds of icmp:
#  https://security.stackexchange.com/questions/22711
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT

-A INPUT -s 192.168.137.0/24 -p tcp -m tcp --dport 53 -j ACCEPT
-A INPUT -s 192.168.137.0/24 -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -i et0 -p udp -m udp --dport 67 -j ACCEPT
COMMIT
# Completed on Wed Feb 21 10:35:52 2018