使用 iptables 允许端口失败

使用 iptables 允许端口失败

我一直在尝试编写一个 bash 脚本,以便使用 iptables 在我的 Debian 服务器上快速打开和关闭端口。我想使用我的脚本在“维护模式”和“服务器 - 游戏模式”之间快速切换,因为我将运行一个游戏服务器。请原谅我在这方面的菜鸟,因为我对 Linux 不是很有经验...

本质上,我将运行三个独立的游戏服务器实例,它们各自在不同的端口上运行。

  • 服务器 A 需要 32000 TCP + UDP32005 TCP
  • 服务器 B 需要 33000 TCP + UDP33005 TCP
  • 服务器 C 需要 34000 TCP + UDP34005 TCP
  • 另外,默认情况下,我允许端口 80 和 443 TCP 用于网络内容(由于某种原因,它们一直被禁用 - 我仍在努力解决这个问题)。

执行我的脚本后,端口 80 可以正常打开,但由于某种原因,我无法打开其余端口......

这是我的脚本的最后状态。

#!/bin/bash
RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[1;32m'
ORANGE='\033[0;33m'
GREY='\033[1;30m'
NC='\033[0m'

echo -e "${ORANGE}Starting default server iptables script${GREY}"

set -o xtrace

iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F

iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

#Web ports configuration
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

#A server ports configuration
iptables -A INPUT -p tcp --dport 32000 -j ACCEPT
iptables -A INPUT -p udp --dport 32000 -j ACCEPT
iptables -A INPUT -p tcp --dport 32005 -j ACCEPT

#B server ports configuration
iptables -A INPUT -p tcp --dport 33000 -j ACCEPT
iptables -A INPUT -p udp --dport 33000 -j ACCEPT
iptables -A INPUT -p tcp --dport 33005 -j ACCEPT

#C server ports configuration
iptables -A INPUT -p tcp --dport 34000 -j ACCEPT
iptables -A INPUT -p udp --dport 34000 -j ACCEPT
iptables -A INPUT -p tcp --dport 34005 -j ACCEPT

iptables -I INPUT 1 -i lo -j ACCEPT
iptables -P INPUT ACCEPT
iptables -A INPUT -j DROP

#Save the iptables
eval "iptables-save > /etc/iptables/rules.v4"

set +o xtrace
echo -e "\n\n\nScript finished executing...! :-)${NC}"

我在用本网站检查我的端口是否打开。

如果你能指出我的错误,我将不胜感激,因为我已经尝试弄清楚两天了:-(

编辑:我刚刚下载了 nmap 并对所有 tcp 端口进行了扫描。出于某种原因,我的端口 32005 是打开的,但其余端口是关闭的。我现在非常非常困惑 :) 请看屏幕截图。 在此处输入图片描述

相关内容