LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: yuanbo203

为什么我在iptables里面没有开3306端口,我将mysql启动后,在本机也能登陆mysql进行操做

[复制链接]
发表于 2007-5-31 12:08:21 | 显示全部楼层
看看你的/etc/my.cnf里是怎么配置的,如果是通过sock连接的iptables应该就限制不了
回复 支持 反对

使用道具 举报

发表于 2007-6-1 09:27:00 | 显示全部楼层
今天试了一下iptables INPUT 和OUTPUT 规则都设置为DROP
/etc/my.cnf里用TCP连接,用mysql本机连一样连上。。。
回复 支持 反对

使用道具 举报

发表于 2007-6-1 13:54:02 | 显示全部楼层
你要确定,,,是用 TCP 连接的噢。。
回复 支持 反对

使用道具 举报

发表于 2007-6-2 00:39:12 | 显示全部楼层
把my.cnf中下面部分的socket改成一个新的文件名,比如:
[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock111

这时连接服务器会出现如下错误:

bumpy:/data1$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock111' (2)

现在用tcp连接看看。没有防火墙,应该可以连上。

bumpy:/data1$ mysql -u root --protocol tcp
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18 to server version: 4.1.15-Debian_1ubuntu5-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
mysql> quit;
Bye

并且有下面的连接记录:

bumpy:/data1$ cat /proc/net/ip_conntrack | grep 3306
tcp      6 106 TIME_WAIT src=127.0.0.1 dst=127.0.0.1 sport=38307 dport=3306 packets=8 bytes=471 src=127.0.0.1 dst=127.0.0.1 sport=3306 dport=38307 packets=5 bytes=355 [ASSURED] mark=0 use=1

加上如下防火墙规则:
bumpy:/data1$ sudo iptables -A INPUT -p tcp --dport 3306 -j DROP

再连:

bumpy:/data1$ mysql -u root --protocol tcp

此时连不上了。

恢复my.cnf回原状,再试:

bumpy:/data1$ mysql -u root --protocol tcp

用tcp还是连不上,用socket就又连上了。

bumpy:/data1$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20 to server version: 4.1.15-Debian_1ubuntu5-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> quit
Bye
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-6-2 09:13:31 | 显示全部楼层
楼上的实验证明,在设置为tcp连接的时候,iptables是要起作用的,而对于socket连接,iptables是不会起作用的
谢谢~~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表