
在 Ubuntu 20.04.3 LTS 上使用 apt 軟體包管理的 MySQL 伺服器版本,並預設安裝 MySQL。
netstat
顯示 MySQL 伺服器已綁定到公用 IPv6 介面:
tcp6 0 0 :::33060 :::* LISTEN 2485/mysqld
tcp6 0 0 :::3306 :::* LISTEN 2485/mysqld
但是,/etc/mysql/mysql.conf.d/mysqld.cnf
顯示(為簡潔起見,刪除了註解行):
[mysqld]
user = mysql
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
我有 iptables 和上游防火牆規則,拒絕外部存取未經批准的連接埠(例如 MySQL),但我更希望 MySQL 本身根據設定檔綁定到系統上的正確介面。
在今年升級到 20.04.3 的另一個系統上,設定檔幾乎相同並netstat
顯示:
tcp 0 0 127.0.0.1:33060 0.0.0.0:* LISTEN 1349/mysqld
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1349/mysqld
答案1
透過將權限更改為/etc/mysql.cnf
0644 解決了這個問題。它被標記為 0777,我絕對沒有這樣做。它是透過mysql-server
apt 軟體包安裝在系統上的。
這可能意味著目前(截至 2021 年 12 月)有一堆 Ubuntu Server 20.04.3 LTS 系統透過 apt 安裝 MySQL,並意外地向世界開放了連接埠 3306。由於預設沒有 root 密碼,這也可能意味著 MySQL 可以從遠端系統快速受到攻擊。