Question

Network firewall / mySQL

Hi all -

This question is regarding outbound firewall for a droplet. Here is droplet configuration:

  • Node server 16.4.0 running behind Nginx
  • App running nestJS/typeorm connecting to mySQL DB on AWS RDS

When trying to open the connection to mySQL DB, get the following error in the logs:

Error: connect ETIMEDOUT
    at PoolConnection._handleTimeoutError (/var/www/html/node_modules/mysql2/lib/connection.js:189:17)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7) {
  errorno: 'ETIMEDOUT',
  code: 'ETIMEDOUT',
  syscall: 'connect',
  fatal: true
}

In DO networking firewalls, if we add UDP ports to outbound rules, then the connection establishes successfully.

Just wondering if there is any explanation to this behavior, i.e. why the need to add UDP for outbound ports as mySQL operates over a TCP port normally.

Any thoughts would be appreciated.

Thanks!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I am using ssh tunnels for MySql access on DO

  1. It is more secure, using a long public key.
  2. I can configure my access always as localhost:3306, no different then my dev configuration locally.
  3. It is more reliable. My experience is that port 3306 seems to be blocked randomly on DO. Ssh, even on a non-standard port always works.
  4. You don’t need to open another port in your firewall. (BTW, you should always change the ssh port from 22 to something harder for hackers to find.)

I am using a daemon in /etc/systemd/system with this executable: /usr/bin/autossh -o “AddressFamily inet” -o “ServerAliveInterval 10” -o “ServerAliveCountMax 3” -N -L ‘3306:localhost:3306’ -p <mysqlsshport> <mysqlhost>

Autossh has one job, to restart the ssh connection if it fails.

Bobby Iliev
Site Moderator
Site Moderator badge
December 4, 2022

Hi there,

I’ve just tried replicating this but wasn’t able to:

  • I’ve set up a new MySQL server
  • Created another Droplet in another region and assigned it to a new firewall
  • On the firewall, I only allowed outbound TCP traffic on port 3306
  • The connection from the Droplet to the MySQL server worked as expected

If you try to run telnet your_rds_instance 3306 do you get a successful connection?

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up