Connection issues: Firewall and IP blocks
Connection issues: Firewall and IP blocks
It is common for connections to be refused when trying to connect your bot or website to an external database (such as MongoDB Atlas) or a third-party API. Most of the time, this is not an error in your code, but rather a security barrier implemented by the target service.
1. Why is the connection blocked?
Square Cloud uses a state-of-the-art infrastructure located in the United States. Many security services and databases feature firewalls that, by default, block incoming access from datacenter and/or foreign IPs to prevent brute-force attacks or unauthorized access.
2. Solution A: Whitelisting via ASN (Recommended)
The most professional and secure way to ensure your application can always connect to a service is to whitelist Square Cloud's ASN (Autonomous System Number) in the target service's firewall.
Since Square uses a dynamic network where your IP changes upon restarting the application, whitelisting the ASN authorizes the entire Square Cloud network. This guarantees that even if your IP changes, your application remains connected without any interruptions.
- Advantage: High security and low maintenance.
- How to do it: Look for "Network Access" or "Whitelisting" settings in the service you are using, and check if they support whitelisting by ASN or IP ranges (CIDR).
3. Solution B: Global Whitelisting (0.0.0.0/0)
For services like MongoDB Atlas or managed database instances, there is an option to allow connections from anywhere in the world.
By configuring the IP access list to 0.0.0.0/0, you are telling the firewall: "Accept connections from any IP, as long as the password/access token is correct."
How to configure it in MongoDB Atlas:
- Access the MongoDB Atlas dashboard.
- Go to Network Access.
- Click on Add IP Address.
- Click the Allow Access From Anywhere button (this will populate
0.0.0.0/0). - Save the changes.
⚠️ Security Note: When using this option, make sure your database password is extremely strong and complex, since the IP barrier will be wide open.
4. Connection Diagnosis
If you have whitelisted the access and still cannot connect, verify the following:
- Connection String: Ensure there are no special characters in the password that require URL Encoding (such as
@or#). - Protocol: Check if the service requires
ssl=trueor specific TLS parameters in the connection URL. - Square Logs: In the dashboard, check if the logs indicate a
Timeouterror (likely a firewall issue) or anAuthentication Failederror (incorrect password).
Updated on: 05/22/2026
Thank you!
