To temporarily close unnecessary database ports in an emergency, you can follow these steps:
Identify the Ports: Determine which database ports are unnecessary (e.g., MySQL defaults to port 3306, PostgreSQL to 5432). Use commands like netstat -tuln (Linux) or Get-NetTCPConnection (Windows PowerShell) to list open ports.
Firewall Rules:
sudo iptables -A INPUT -p tcp --dport 3306 -j DROP
New-NetFirewallRule to block the port.New-NetFirewallRule -DisplayName "Block DB Port 3306" -Direction Inbound -LocalPort 3306 -Protocol TCP -Action Block
Database Configuration: Some databases allow binding to 127.0.0.1 (localhost) only, restricting external access. For example, in MySQL, modify my.cnf to set bind-address = 127.0.0.1.
Cloud Provider Security Groups (if applicable): If the database is hosted on a cloud platform like Tencent Cloud, use the Security Group feature to revoke inbound rules for the unnecessary ports.
Verify: Test the port closure with telnet<IP> <port> or nc -zv<IP> <port> to ensure the port is no longer accessible.
For Tencent Cloud, you can manage ports via:
This ensures minimal exposure while you address the emergency.