Skip to content

Commit 21a310b

Browse files
committed
Implement additional rules for LXC and DNS communication.
1 parent 27ad300 commit 21a310b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

bin/v-update-firewall

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@ for line in $(sort -r -n -k 2 -t \' $rules); do
112112
fi
113113
done
114114

115+
# Check if is LXC
116+
if grep --quiet container=lxc /proc/1/environ; then
117+
# Get active dns servers /etc/resolv.conf
118+
DNS_SERVER=$(cat /etc/resolv.conf | grep -v '^#' | grep nameserver | awk '{print $2}')
119+
120+
# Add iptable rules for dns server
121+
for ip in $DNS_SERVER
122+
do
123+
echo "$iptables -A OUTPUT -p udp -d $ip --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT" >> $tmp
124+
echo "$iptables -A INPUT -p udp -s $ip --sport 53 -m state --state ESTABLISHED -j ACCEPT" >> $tmp
125+
echo "$iptables -A OUTPUT -p tcp -d $ip --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT" >> $tmp
126+
echo "$iptables -A INPUT -p tcp -s $ip --sport 53 -m state --state ESTABLISHED -j ACCEPT" >> $tmp
127+
done
128+
fi
129+
115130
# Switching chain policy to DROP
116131
echo "$iptables -P INPUT DROP" >> $tmp
117132

0 commit comments

Comments
 (0)