How to Enable Firewall Incoming Database Connections

The firewall on the database server may block incoming remote TCP/IP connections. To enable these connections, you need to configure the firewall to allow traffic through the database's port.

Common Database Ports

  • SQL Server: 1433
  • MySQL: 3306
  • PostgreSQL: 5432
  • Oracle Database: 1521
  • MongoDB: 27017

You will need to identify the port used by your database. If the port has been customized, use the updated value instead of the defaults.

For Windows Servers

Using Command Prompt:

1. Open Command Prompt as an administrator by right-clicking and selecting Run as Administrator.

2. Run the following command, replacing 1433 with your database's port number:

netsh advfirewall firewall add rule name="DatabasePort" dir=in action=allow protocol=TCP localport=1433
    

Using Windows Firewall:

  1. Search for Windows Firewall with Advanced Security in the Start menu.
  2. Setup Windows Firewall for database connectivity

  3. In the left pane, right-click Inbound Rules, and select New Rule.
  4. Firewall 2
  5. Follow these steps:
    • Rule Type: Select Port.
    • Protocol and Ports: Choose TCP and specify the port number (e.g., 1433 for SQL Server).
    • Action: Select Allow the connection.
    • Profile: Select the profiles (Domain, Private, or Public) where this rule applies.
    • Name: Enter a descriptive name (e.g., "Allow SQL 1433 Inbound").
  6. Click Finish to save the rule.

For Linux Servers

For Linux, you may need to configure the firewall using tools like ufw, iptables, or firewalld. Here's an example with ufw:

sudo ufw allow 3306/tcp
    

Replace 3306 with your database's port. You can search online for detailed instructions based on your distribution and firewall tool.

Additional Considerations

  • Always ensure that your firewall rules are secure and only allow connections from trusted IP addresses if possible.
  • For cloud-hosted databases, check the provider's documentation for enabling remote access through the cloud firewall.
  • If you encounter issues, verify that the database server itself is configured to accept remote connections.