← back to Handbag Authentication
scripts/configure-firewall.sh
55 lines
#!/bin/bash
echo "=== Configuring Firewall for Port 7989 ==="
echo ""
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root or with sudo:"
echo "sudo bash scripts/configure-firewall.sh"
exit 1
fi
# Detect firewall system
if command -v ufw &> /dev/null; then
echo "✓ UFW detected"
echo "Opening port 7989..."
ufw allow 7989/tcp
ufw reload
echo "✓ Port 7989 opened in UFW"
ufw status | grep 7989
elif command -v firewall-cmd &> /dev/null; then
echo "✓ firewalld detected"
echo "Opening port 7989..."
firewall-cmd --permanent --add-port=7989/tcp
firewall-cmd --reload
echo "✓ Port 7989 opened in firewalld"
firewall-cmd --list-ports | grep 7989
elif command -v iptables &> /dev/null; then
echo "✓ iptables detected"
echo "Opening port 7989..."
iptables -A INPUT -p tcp --dport 7989 -j ACCEPT
# Try to save (different methods for different systems)
if command -v iptables-save &> /dev/null; then
iptables-save > /etc/iptables/rules.v4 2>/dev/null || \
iptables-save > /etc/sysconfig/iptables 2>/dev/null || \
echo "Note: iptables rules may not persist after reboot. Please configure your system to save iptables rules."
fi
echo "✓ Port 7989 opened in iptables"
else
echo "⚠ No firewall detected or already configured"
echo "If you're using a cloud provider (AWS, GCP, Azure), configure the security group manually:"
echo "- Protocol: TCP"
echo "- Port: 7989"
echo "- Source: 0.0.0.0/0 (or specific IP range)"
fi
echo ""
echo "=== Firewall Configuration Complete ==="
echo ""
echo "Your server should now be accessible on port 7989"
echo "Test with: curl http://localhost:7989"