allow_essential_output_traffic.sh
· 200 B · Bash
原始檔案
# 僅允許必要的 OUTPUT 流量
iptables -A OUTPUT -o eth0 -p tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --dport 443 -j ACCEPT
iptables -A OUTPUT -o eth0 -p udp --dport 53 -j ACCEPT
| 1 | # 僅允許必要的 OUTPUT 流量 |
| 2 | iptables -A OUTPUT -o eth0 -p tcp --dport 80 -j ACCEPT |
| 3 | iptables -A OUTPUT -o eth0 -p tcp --dport 443 -j ACCEPT |
| 4 | iptables -A OUTPUT -o eth0 -p udp --dport 53 -j ACCEPT |
check_network_interface_and_iptables.sh
· 266 B · Bash
原始檔案
# 檢查網卡是否存在
if ! ip link show $LAN_IFACE > /dev/null 2>&1; then
echo "錯誤:內網網卡 $LAN_IFACE 不存在!"
exit 1
fi
# 檢查 iptables 命令是否成功
iptables -P INPUT DROP || { echo "設置 INPUT 鏈策略失敗!"; exit 1; }
| 1 | # 檢查網卡是否存在 |
| 2 | if ! ip link show $LAN_IFACE > /dev/null 2>&1; then |
| 3 | echo "錯誤:內網網卡 $LAN_IFACE 不存在!" |
| 4 | exit 1 |
| 5 | fi |
| 6 | |
| 7 | # 檢查 iptables 命令是否成功 |
| 8 | iptables -P INPUT DROP || { echo "設置 INPUT 鏈策略失敗!"; exit 1; } |
| 9 |
restrict_ssh_access_by_subnet.sh
· 149 B · Bash
原始檔案
# 限制 SSH 訪問僅允許特定子網
iptables -A INPUT -p tcp --dport 22 -s 192.168.6.0/24 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j DROP
| 1 | # 限制 SSH 訪問僅允許特定子網 |
| 2 | iptables -A INPUT -p tcp --dport 22 -s 192.168.6.0/24 -j ACCEPT |
| 3 | iptables -A INPUT -p tcp --dport 22 -j DROP |
| 4 |