21-firewall.sh
54 lines
| 1.9 KiB
| application/x-sh
|
BashLexer
/ bootstrap.d / 21-firewall.sh
Filip Pytloun
|
r56 | # | ||
Jan Wagner
|
r67 | # Setup Firewall | ||
Filip Pytloun
|
r56 | # | ||
Jan Wagner
|
r67 | # Load utility functions | ||
Filip Pytloun
|
r56 | . ./functions.sh | ||
if [ "$ENABLE_IPTABLES" = true ] ; then | ||||
# Create iptables configuration directory | ||||
drtyhlpr
|
r94 | mkdir -p "${ETC_DIR}/iptables" | ||
Unknown
|
r279 | |||
Unknown
|
r502 | if [ "$KERNEL_NF" = false ] ; then | ||
Unknown
|
r569 | # iptables-save and -restore are slaves of iptables and thus are set accordingly | ||
Unknown
|
r502 | chroot_exec update-alternatives --verbose --set iptables /usr/sbin/iptables-legacy | ||
fi | ||||
Unknown
|
r279 | |||
Jan Wagner
|
r71 | # Install iptables systemd service | ||
drtyhlpr
|
r94 | install_readonly files/iptables/iptables.service "${ETC_DIR}/systemd/system/iptables.service" | ||
Filip Pytloun
|
r56 | |||
Jan Wagner
|
r71 | # Install flush-table script called by iptables service | ||
drtyhlpr
|
r94 | install_exec files/iptables/flush-iptables.sh "${ETC_DIR}/iptables/flush-iptables.sh" | ||
Filip Pytloun
|
r56 | |||
Jan Wagner
|
r71 | # Install iptables rule file | ||
drtyhlpr
|
r94 | install_readonly files/iptables/iptables.rules "${ETC_DIR}/iptables/iptables.rules" | ||
Filip Pytloun
|
r56 | |||
# Reload systemd configuration and enable iptables service | ||||
chroot_exec systemctl daemon-reload | ||||
chroot_exec systemctl enable iptables.service | ||||
if [ "$ENABLE_IPV6" = true ] ; then | ||||
Unknown
|
r502 | if [ "$KERNEL_NF" = false ] ; then | ||
Unknown
|
r569 | # iptables-save and -restore are slaves of iptables and thus are set accordingly | ||
drtyhlpr
|
r530 | chroot_exec update-alternatives --verbose --set ip6tables /usr/sbin/ip6tables-legacy | ||
Unknown
|
r569 | fi | ||
Jan Wagner
|
r71 | # Install ip6tables systemd service | ||
drtyhlpr
|
r94 | install_readonly files/iptables/ip6tables.service "${ETC_DIR}/systemd/system/ip6tables.service" | ||
Filip Pytloun
|
r56 | |||
Jan Wagner
|
r71 | # Install ip6tables file | ||
drtyhlpr
|
r94 | install_exec files/iptables/flush-ip6tables.sh "${ETC_DIR}/iptables/flush-ip6tables.sh" | ||
Filip Pytloun
|
r56 | |||
drtyhlpr
|
r94 | install_readonly files/iptables/ip6tables.rules "${ETC_DIR}/iptables/ip6tables.rules" | ||
Filip Pytloun
|
r56 | |||
# Reload systemd configuration and enable iptables service | ||||
chroot_exec systemctl daemon-reload | ||||
chroot_exec systemctl enable ip6tables.service | ||||
fi | ||||
drtyhlpr
|
r240 | |||
Unknown
|
r732 | if [ "$SSH_ENABLE" = false ] ; then | ||
drtyhlpr
|
r240 | # Remove SSHD related iptables rules | ||
sed -i "/^#/! {/SSH/ s/^/# /}" "${ETC_DIR}/iptables/iptables.rules" 2> /dev/null | ||||
sed -i "/^#/! {/SSH/ s/^/# /}" "${ETC_DIR}/iptables/ip6tables.rules" 2> /dev/null | ||||
fi | ||||
Filip Pytloun
|
r56 | fi | ||