在Linux系統中,常見的防火墻工具有iptables和firewalld。以下是關于如何開啟和關閉這些防火墻的詳細步驟:
臨時開啟:
sudo iptables -P INPUT DROP
sudo iptables -P FORWARD DROP
sudo iptables -P OUTPUT ACCEPT
永久開啟:
/etc/sysctl.conf
文件,添加或修改以下行:net.ipv4.ip_forward=1
sudo sysctl -p
sudo iptables-save > /etc/iptables/rules.v4
/etc/network/if-pre-up.d/iptables
,內容如下:#!/bin/sh
iptables-restore < /etc/iptables/rules.v4
sudo chmod +x /etc/network/if-pre-up.d/iptables
臨時關閉:
sudo iptables -F
sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
永久關閉:
sudo rm /etc/network/if-pre-up.d/iptables
sudo iptables-save > /dev/null
臨時開啟:
sudo systemctl start firewalld
永久開啟:
sudo systemctl enable firewalld
臨時關閉:
sudo systemctl stop firewalld
永久關閉:
sudo systemctl disable firewalld
firewall-cmd
命令來管理規則,例如:sudo firewall-cmd --list-all
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload
通過以上步驟,你可以輕松地在Linux系統中開啟和關閉iptables和firewalld防火墻。