在 Debian 上给 Tomcat 配置防火墙,通常有两种常见做法:使用 UFW(推荐,简单) 或 使用 iptables/nftables(更底层)。下面以 UFW 为主说明,并补充 iptables 示例。
Tomcat 默认端口:
假设你要开放 8080。
sudo apt update
sudo apt install ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 8080/tcp
如果你用 HTTPS(如 8443):
sudo ufw allow 8443/tcp
sudo ufw enable
sudo ufw status
示例输出:
8080/tcp ALLOW Anywhere
22/tcp ALLOW Anywhere
只允许内网访问:
sudo ufw allow from 192.168.1.0/24 to any port 8080
只允许单个 IP:
sudo ufw allow from 203.0.113.10 to any port 8080
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -P INPUT DROP
保存(Debian):
apt install iptables-persistent
netfilter-persistent save
<!-- <Connector port="8009" protocol="AJP/1.3" /> -->
<Connector port="8080" address="127.0.0.1" />
ss -tulnp | grep java
如果你愿意,可以告诉我:
我可以给你更精确的配置方案。