禁止Mysql默认端口被主机以外访问

转载本站文章请注明,转载自:昕星谷[http://oneyicn.gobaiyi.com]
本文链接: 禁止Mysql默认端口被主机以外访问">http://oneyicn.gobaiyi.com/archives/944/

研究Mysql的时候,发现3306对所有端口开放着,感觉不安全。

netstat -anlp | grep
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 638/mysqld
unix 2 [ ACC ] STREAM LISTENING 12305521 638/mysqld /tmp/mysql.sock

F Host ’192.168.1.242′ is not allowed to connect to this MySQL server失去了跟主机的连接。

当然,也可以用Iptables来实现。不过有更好又简单的方法。

引用Chinaunix文章所说:

* 安全配置* 为了数据的安全,可以考虑让MySQL只守候在127.0.0.1上,这样从Internet上就无法直接访问数据库了。 修改/etc/init.d/mysql文件 在start部分找到类似下面这行
$bindir/mysqld_safe –datadir=$datadir –pid-file=$pid_file &
修改成
$bindir/mysqld_safe –datadir=$datadir –pid-file=$pid_file –bind-address=127.0.0.1 &
重起MySQL/etc/init.d/mysql restart
最后netstat -l确认一下:
tcp 0 0 localhost:mysql *:* LISTEN

OK

而我修改/etc/init.d/mysq,找到:
把原先的

/usr/bin/mysqld_safe –defaults-file=/etc/my.cnf –pid-file=”$mypidfile” –log-error=”$errlogfile” >/dev/null 2>&1 &


变为

/usr/bin/mysqld_safe –defaults-file=/etc/my.cnf –pid-file=”$mypidfile” –log-error=”$errlogfile” –bind-address=127.0.0.1 &

重启mysql:/etc/init.d/mysql restart

查看后实现:netstat -anlp | grep mysql

tcp         0       0 127.0.0.1:3306               0.0.0.0:*                   LIST

telnet 192.168.1.241 3306
正在连接到192.168.1.241…不能打开到主机的连接, 在端口 3306: 连接失败

随机文章推荐

2009年12月19日 | 归档于 linux, 网络
本文目前尚无任何评论.

发表评论

XHTML: 您可以使用这些标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

无觅相关文章插件,快速提升流量