Chinaunix首页 | 论坛 | 博客
  • 博客访问: 92337059
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: Mysql/postgreSQL

2008-04-29 15:01:30


去查询Mysql的时候,都见3306对所有端口开放着,感觉不安全。
netstat -anlp | grep mysql
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来实现,不过好像还是不行。

iptables -A INPUT -p tcp -s $ANY --dport 3306 -j DROP

引用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: 连接失败
阅读(810) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~