Iptables 配置如下
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1:152]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -s 127.0.0.1/32 -p tcp -m tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3306 -j DROP
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8989 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
但是还是开启不了 8080 端口
执行 services iptables status 如下
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED, ESTABLISHED
3 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
4 ACCEPT tcp -- 127.0.0.1 0.0.0.0/0 tcp dpt:3306
5 DROP tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3306
6 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:8989
7 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED, ESTABLISHED
8 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
9 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
10 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
11 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080
12 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with ic mp-host-prohibited
Chain FORWARD (policy ACCEPT )
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with ic mp-host-prohibited
Chain OUTPUT (policy ACCEPT )
num target prot opt source destination
1
Pangdouya 2015-09-01 12:47:01 +08:00 via iPhone
11 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080
不是开启了吗?重启时用 iptables-restore 恢复。 |
2
nekoyaki 2015-09-01 12:47:08 +08:00
什么叫“还是开启不了该端口”,或者说你是凭借什么,认为你“开启不了该端口”?
|
3
nekoyaki 2015-09-01 12:48:19 +08:00
@Pangdouya
看他这个命令应该是 redhat/centos , 不像 debian 系, redhat 系不需要手动执行 iptables-restore 的。 |
4
Pangdouya 2015-09-01 12:57:45 +08:00 via iPad
@nekoyaki 谢谢指出。我说的是 debian 系下的做法, redhat/centos 我不太清楚。
|
5
uleh 2015-09-01 12:59:14 +08:00
1. 把规则写到 /etc/sysconfig/iptables
2. sudo systemctl restart iptables.service 3. 确认防火墙状态 |
8
nekoyaki 2015-09-01 17:16:21 +08:00
|
9
moxiaotiao OP @nekoyaki 用在线端口检测工具,检测不到该端口处于开放状态
|
10
moxiaotiao OP @nekoyaki Centos 6.8 系统
|
12
uleh 2015-09-01 18:09:28 +08:00
@moxiaotiao 看我写的第三步,试试 systemctl status firewalld.service (这个才是正牌「防火墙」)
|
13
moxiaotiao OP @uleh 恩,我试试
|
16
nekoyaki 2015-09-01 19:04:17 +08:00
|
17
zent00 2015-09-01 19:18:34 +08:00
|