iptables 开启3306端口

[[email protected] ~]# mysql -uroot -h 192.168.1.35 -p
Enter password:
ERROR 1130 (HY000): Host ‘192.168.1.66‘ is not allowed to connect to this MySQL server

下表可见3306端口没打开:

[[email protected] online]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22
2    ACCEPT     all  --  127.0.0.1            127.0.0.1
3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:22 state ESTABLISHED
2    ACCEPT     all  --  127.0.0.1            0.0.0.0/0
3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:80 state ESTABLISHED
[[email protected] online]# iptables -A INPUT -p tcp -s 192.168.1.66 --dport 3306 -j ACCEPT
[[email protected] online]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22
2    ACCEPT     all  --  127.0.0.1            127.0.0.1
3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80
4    ACCEPT     tcp  --  192.168.1.66         0.0.0.0/0           tcp dpt:3306 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:22 state ESTABLISHED
2    ACCEPT     all  --  127.0.0.1            0.0.0.0/0
3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:80 state ESTABLISHED

建个远程账户:

mysql> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
+------+-----------+-------------------------------------------+
1 row in set (0.06 sec)
mysql> grant select on *.* to "select_user"@"%" identified by "123";
Query OK, 0 rows affected (0.10 sec)
mysql> select user,host,password from user;
+-------------+-----------+-------------------------------------------+
| user        | host      | password                                  |
+-------------+-----------+-------------------------------------------+
| root        | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| select_user | %         | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
+-------------+-----------+-------------------------------------------+
2 rows in set (0.00 sec)

成功连入远程连入mysql服务器:

[[email protected] ~]# mysql -uselect_user -h192.168.1.35 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.5.40-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql>

关掉3306端口,再次测试:

[[email protected] online]# iptables -D INPUT -p tcp -s 192.168.1.66 --dport 3306 -j ACCEPT
[[email protected] online]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22
2    ACCEPT     all  --  127.0.0.1            127.0.0.1
3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:22 state ESTABLISHED
2    ACCEPT     all  --  127.0.0.1            0.0.0.0/0
3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:80 state ESTABLISHED
[[email protected] online]# iptables -P INPUT DROP
[[email protected] online]# iptables -P OUTPUT DROP
[[email protected] online]# iptables -P FORWARD DROP
[[email protected] online]# service iptables status
Table: filter
Chain INPUT (policy DROP)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22
2    ACCEPT     all  --  127.0.0.1            127.0.0.1
3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80 

Chain FORWARD (policy DROP)
num  target     prot opt source               destination         

Chain OUTPUT (policy DROP)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:22 state ESTABLISHED
2    ACCEPT     all  --  127.0.0.1            0.0.0.0/0
3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:80 state ESTABLISHED
[[email protected] ~]# mysql -uselect_user -h192.168.1.35 -p
Enter password: 

#卡主无法链接

重新开启3306端口:

[[email protected] online]# service iptables status
Table: filter
Chain INPUT (policy DROP)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:3306
2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22
3    ACCEPT     all  --  127.0.0.1            127.0.0.1
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80 

Chain FORWARD (policy DROP)
num  target     prot opt source               destination         

Chain OUTPUT (policy DROP)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:3306
2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:22 state ESTABLISHED
3    ACCEPT     all  --  127.0.0.1            0.0.0.0/0
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:80 state ESTABLISHED 

[[email protected] online]# cat /etc/sysconfig/ip
ip6tables         ip6tables.old     iptables-config   iptables.save
ip6tables-config  iptables          iptables.old
[[email protected] online]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Wed Jun  1 22:15:41 2016
*filter
:INPUT DROP [24:3081]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
-A OUTPUT -p tcp -m tcp --sport 3306 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -s 127.0.0.1/32 -d 127.0.0.1/32 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A OUTPUT -p tcp -m tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
-A OUTPUT -s 127.0.0.1/32 -j ACCEPT
-A OUTPUT -p tcp -m tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
COMMIT
# Completed on Wed Jun  1 22:15:41 2016
时间: 2024-11-10 07:52:31

iptables 开启3306端口的相关文章

Centos7防火墙开启3306端口

CentOS7的默认防火墙为firewall,且默认是不打开的. systemctl start firewalld # 启动friewall systemctl status firewalld # 查看firewall启动情况 firewall-cmd --zone=public --add-port=3306/tcp --permanent # 开启3306端口 firewalld   # firewall-cmd --reload 重启 firewall-cmd --query-port

linux下如何修改iptables开启80端口(2)

vi /etc/sysconfig/iptables-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允许80端口通过防火墙)-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT(允许3306端口通过防火墙)特别提示:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,正确的应该是添加到默认的22端口这条规则的下面添加好之后防火墙

Linux iptables开启80端口

Linux下安装好apache的时候 测试apache 监听的端口80#netstat -lnt |grep 80tcp        0      0 :::80                      :::*                        LISTEN  安装成功了! 想到用本机telnet IP 80 不通- -  但是telnet IP 22  通了 ~ ~ 可能是80端口没开放.于是 开启80端口 1.开启80端口命令:/sbin/iptables -I INPUT

windows开启3306端口访问mysql

开启 MySQL 的远程登陆帐号有两大步: 1.确定服务器上的防火墙没有阻止 3306 端口. MySQL 默认的端口是 3306 ,需要确定防火墙没有阻止 3306 端口,否则远程是无法通过 3306 端口连接到 MySQL 的. 如果您在安装 MySQL 时指定了其他端口,请在防火墙中开启您指定的 MySQL 使用的端口号. 如果不知道怎样设置您的服务器上的防火墙,请向您的服务器管理员咨询. 2.增加允许远程连接 MySQL 用户并授权. 1)首先以 root 帐户登陆 MySQL 在 Wi

CentOs7 使用iptables开启关闭端口

介绍 iptables命令是Linux上常用的防火墙软件,是netfilter项目的一部分 iptables文件设置路径:命令:vim /etc/sysconfig/iptables-config 注意事项 如果说你以前使用的是contos7 那么默认使用的防火墙那么就是Firewall 这样的话,就要先把Firewall 给关闭在使用iptables 关闭Firewall 命令 命令:systemctl stop firewalld #关闭防火墙 命令:systemctl disable fi

linux下如何修改iptables开启80端口

最近在做本地服务器的环境,发现网站localhost能正常访问,用ip访问就访问不了,经常使用CentOS的朋友,可能会遇到和我一样的问题.开启了防火墙导致80端口无法访问,刚开始学习centos的朋友可以参考下. www.2cto.com 经常使用CentOS的朋友,可能会遇到和我一样的问题.最近在Linux CentOS防火墙下安装配置 ORACLE 数据库的时候,总显示因为网络端口而导致的EM安装失败,遂打算先关闭一下CentOS防火墙.偶然看到CentOS防火墙的配置操作说明,感觉不错.

【linux】iptables 开启80端口

经常使用CentOS的朋友,可能会遇到和我一样的问题.开启了防火墙导致80端口无法访问,刚开始学习centos的朋友可以参考下. 经常使用CentOS的朋友,可能会遇到和我一样的问题.最近在Linux CentOS防火墙下安装配置 ORACLE  数据库的时候,总显示因为网络端口而导致的EM安装失败,遂打算先关闭一下CentOS防火墙.偶然看到CentOS防火墙的配置操作说明,感觉不错.执 行”setup”命令启动文字模式配置实用程序,在”选择一种工具”中选择”防火墙配置”,然后选择”运行工具”

iptables 开启80端口

[[email protected] online]# iptables -F#清空规则 [[email protected] online]# iptables -L# Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target

使用Windows 2003服务器,进行Mysql 远程登录或者主从同步时,要开启3306端口

开始->控制面板->windows防火墙->“例外”选项卡->添加端口->3306->确定 其它情况: 关于windows2003服务器,mysql不能远程登录的问题解决 http://blog.sina.com.cn/s/blog_a02b996d01018rm3.html 原文地址:https://www.cnblogs.com/xtmp/p/12629464.html