From 42ba0ea2857974110c8fdcf644a1106041916333 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 18 Jan 2023 17:27:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96iptables=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/firewall_api.py | 3 ++- scripts/install/debian.sh | 12 ++++++++---- scripts/install/rhel.sh | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/class/core/firewall_api.py b/class/core/firewall_api.py index 38fe807d7..69dbc2664 100755 --- a/class/core/firewall_api.py +++ b/class/core/firewall_api.py @@ -33,7 +33,8 @@ class firewall_api: __isMac = False def __init__(self): - if os.path.exists('/usr/sbin/iptables'): + iptables_file = mw.systemdCfgDir() + '/iptables.service' + if os.path.exists(iptables_file): self.__isIptables = True if os.path.exists('/usr/sbin/firewalld'): self.__isFirewalld = True diff --git a/scripts/install/debian.sh b/scripts/install/debian.sh index b3c78a09c..5b5f8a05f 100644 --- a/scripts/install/debian.sh +++ b/scripts/install/debian.sh @@ -50,7 +50,6 @@ if [ -f /usr/sbin/ufw ];then # ufw allow 7200/tcp # ufw allow 3306/tcp # ufw allow 30000:40000/tcp - fi if [ -f /usr/sbin/ufw ];then @@ -58,8 +57,13 @@ if [ -f /usr/sbin/ufw ];then fi if [ ! -f /usr/sbin/ufw ];then + # look + # firewall-cmd --list-all + apt install -y firewalld systemctl enable firewalld + #取消服务锁定 + systemctl unmask firewalld systemctl start firewalld firewall-cmd --permanent --zone=public --add-port=22/tcp @@ -75,10 +79,10 @@ if [ ! -f /usr/sbin/ufw ];then sed -i 's#IndividualCalls=no#IndividualCalls=yes#g' /etc/firewalld/firewalld.conf firewall-cmd --reload -fi -#安装时不开启 -systemctl stop firewalld + #安装时不开启 + systemctl stop firewalld +fi #fix zlib1g-dev fail echo -e "\e[0;32mfix zlib1g-dev install question start\e[0m" diff --git a/scripts/install/rhel.sh b/scripts/install/rhel.sh index b7e3ab976..a7deb3661 100644 --- a/scripts/install/rhel.sh +++ b/scripts/install/rhel.sh @@ -47,7 +47,8 @@ if [ -f /usr/sbin/iptables ];then # iptables -P FORWARD DROP iptables -P INPUT DROP iptables -P OUTPUT ACCEPT - + iptables -A INPUT -p tcp -s 127.0.0.1 -j ACCEPT + iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT