Your laptop cannot reach an RDS database, and ping does not work either
Could not connect to server: Connection timed outShort answer
When a client times out against an RDS endpoint, the network path is blocked, not the database login. Test the port with nc first. Then check four things in order: the security group's inbound rule for your IP, the instance's Public access setting, the subnet's route to an internet gateway, and a local firewall or busy local port. Ping never works on RDS.
Fix it fast
1Find out which cause you have
Test the TCP port instead of using ping. Amazon RDS does not accept ICMP traffic, so a failed ping tells you nothing. Replace the endpoint and port (3306 for MySQL, 5432 for PostgreSQL) with your own. A success message means the network path is open and the problem is the login; a hang or failure means one of the causes below.
nc -zv mydb.xxxx.us-east-1.rds.amazonaws.com 33062Match what you see, then jump to its fix
- 1
nc hangs and then fails, while the instance status is availableThe security group has no inbound rule for your addressFix - 2
The console shows Public access: No for the instanceThe instance is not publicly accessibleFix - 3
Public access is Yes and the security group is open, but the connection still times outThe subnets have no route to an internet gatewayFix - 4
Other sites work, the RDS rules look right, and the test only fails from this networkYour own network blocks the port, or the port is taken locallyFix
- 1
What does the error look like?
Could not connect to server: Connection timed outPing to the RDS endpoint gets no reply
Cause 1 of 4
The security group has no inbound rule for your address
1Check
RDS instances allow no access by default. Access comes from the security group attached to the instance, and a rule must allow your current public IP on the database port. Look at the group in the instance's Connectivity & security tab.
aws rds describe-db-instances --db-instance-identifier mydb \
--query "DBInstances[0].VpcSecurityGroups[].VpcSecurityGroupId"2Fix
Add an inbound rule for the database port. In the console choose My IP as the source, which uses the address your browser shows. Note that connections from 169.254.0.0/16 are never allowed.
aws ec2 authorize-security-group-ingress --group-id sg-0123456789abcdef0 \
--protocol tcp --port 3306 --cidr 203.0.113.25/323Verify
Run the port test again.
nc -zv mydb.xxxx.us-east-1.rds.amazonaws.com 3306Confirmed by docs.aws.amazon.com
Cause 2 of 4
The instance is not publicly accessible
1Check
To reach an instance from outside its VPC, for example from your own computer, it needs a public IP address. That is the Public access setting.
aws rds describe-db-instances --db-instance-identifier mydb \
--query "DBInstances[0].PubliclyAccessible"2Fix
Modify the instance and set Public access to Yes. If you would rather keep the database private, connect from inside the VPC instead, for example from an EC2 instance in the same VPC.
aws rds modify-db-instance --db-instance-identifier mydb \
--publicly-accessible --apply-immediately3Verify
Wait until the instance status is available, then repeat the port test.
nc -zv mydb.xxxx.us-east-1.rds.amazonaws.com 3306Confirmed by docs.aws.amazon.com
Cause 3 of 4
The subnets have no route to an internet gateway
1Check
A publicly accessible instance needs the subnets of its DB subnet group to have an internet gateway. In the VPC console, open the subnet's route table and look for a route with destination 0.0.0.0/0 whose target is the internet gateway (and ::/0 as well if you connect over IPv6).
# VPC console > Subnets > pick the subnet > Route table tab: is 0.0.0.0/0 sent to an igw-... target?2Fix
Attach an internet gateway to the VPC if there is none, then add the 0.0.0.0/0 route (and ::/0 for IPv6) pointing at it in the route table of each subnet in the DB subnet group.
aws ec2 create-route --route-table-id rtb-0123456789abcdef0 \
--destination-cidr-block 0.0.0.0/0 --gateway-id igw-0123456789abcdef03Verify
Repeat the port test from your machine.
nc -zv mydb.xxxx.us-east-1.rds.amazonaws.com 3306Confirmed by docs.aws.amazon.com
Cause 4 of 4
Your own network blocks the port, or the port is taken locally
1Check
A company or home firewall can block outbound traffic to the database port. For PostgreSQL the default 5432 can also be occupied on your computer by a local PostgreSQL server, so the client talks to that one instead. Try the same test from a different network, and see what listens locally.
nc -zv localhost 54322Fix
Ask the network administrator to allow the port, or modify the instance to use a different database port (and open that port in the security group). Stop or move the local service if it holds the same port.
aws rds modify-db-instance --db-instance-identifier mydb \
--db-port-number 5433 --apply-immediately3Verify
Test the new port from the affected network.
nc -zv mydb.xxxx.us-east-1.rds.amazonaws.com 5433Confirmed by docs.aws.amazon.com
How do I stop it coming back?
- Use the instance endpoint name, not an IP address, in every connection string.
- Keep database access in a security group you name and document; avoid 0.0.0.0/0 on the database port.
- Test with nc -zv, never with ping, when you check RDS reachability.
- Prefer a private database reached from inside the VPC for production, and open Public access only for short work.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
An EC2 instance cannot reach its RDS database
Could not open connection to the host, on port <port>: Connect failed
RDS denies all access until a security group allows it.
3 causes, each with a fixDatabases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fixDatabases
DBeaver cannot run pg_restore: the utility is not found in the client home
Utility 'pg_restore' not found in client home '/usr/lib' (/usr/lib)
DBeaver runs pg_restore from a local PostgreSQL client folder; it does not bundle one.
3 causes, each with a fixDatabases
python manage.py migrate finishes but the tables for my app are missing
relation "myapp_book" does not exist
migrate only applies migration files that exist.
3 causes, each with a fixDatabases
Django cannot connect to PostgreSQL: connection refused on port 5432, locally or in Docker
Is the server running on that host and accepting TCP/IP connections?
Connection refused means nothing accepted the connection at the host and port Django used.
4 causes, each with a fix