This guide covers the specific scenario of managing UFW on a guest VM inside a CloudStack environment, explaining why external IP rules often fail and how to fix them.
Run this command on your VM while attempting a connection from your external client to see what UFW is actually detecting:
tail -f /var/log/ufw.log | grep 3306
Look for: [UFW BLOCK] ... SRC=10.1.1.1 DST=10.1.1.161 ... DPT=3306. The SRC value here is what you must whitelist in UFW.
Restrict access at the infrastructure level via the CloudStack UI.
Trust the traffic coming from the Virtual Router gateway.
# Allow Gateway IP
ufw allow from 10.1.1.1 to any port 3306 proto tcp
ufw reload
| Feature | Recommended Setting |
|---|---|
| MySQL Bind Address | Set to 0.0.0.0 or the internal IP in mysqld.cnf. |
| CloudStack Firewall | Whitelist the Real Client IP. |
| UFW Rule | Whitelist the Virtual Router Gateway IP. |