#!/bin/bash # 快速开放端口 29419 的脚本 echo "==========================================" echo "快速开放 Gerrit SSH 端口 29419" echo "==========================================" if [ "$EUID" -ne 0 ]; then echo "❌ 需要 root 权限,请使用 sudo 运行" echo "使用方法: sudo bash 快速开放端口29419.sh" exit 1 fi echo "" echo "步骤 1: 检查防火墙类型..." # 检查 firewalld if systemctl is-active --quiet firewalld 2>/dev/null; then echo "✅ 检测到 firewalld 正在运行" echo " 使用 firewalld 配置..." firewall-cmd --permanent --add-port=29419/tcp firewall-cmd --reload if firewall-cmd --list-ports | grep -q "29419/tcp"; then echo "✅ 端口 29419 已通过 firewalld 开放" else echo "❌ firewalld 配置失败" fi else echo "⚠️ firewalld 未运行,使用 iptables 配置..." # 使用 iptables iptables -I INPUT -p tcp --dport 29419 -j ACCEPT # 保存规则 if [ -f /etc/sysconfig/iptables ]; then iptables-save > /etc/sysconfig/iptables echo "✅ iptables 规则已保存" else echo "⚠️ 请手动保存 iptables 规则" fi if iptables -L -n | grep -q "29419"; then echo "✅ 端口 29419 已通过 iptables 开放" else echo "❌ iptables 配置失败" fi fi echo "" echo "步骤 2: 验证端口监听..." if netstat -tlnp | grep -q ":29419"; then echo "✅ Gerrit 正在监听端口 29419" netstat -tlnp | grep 29419 else echo "⚠️ 警告:未检测到端口 29419 监听" fi echo "" echo "==========================================" echo "完成!" echo "==========================================" echo "" echo "请从客户端测试连接:" echo " ssh -p 29419 renjianbo@101.43.95.130 gerrit version" echo ""