iptables 开放80端口以及删除80端口的规则

时间:2024-03-04 15:22:10
[root@zabbix-server html]# iptables --version
iptables v1.4.21

[root@zabbix-server html]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@zabbix-server html]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:http
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 

[root@zabbix-server html]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ 确定 ]

 

测试访问

 

删除刚刚添加的80端口

[root@zabbix-server html]# iptables -D INPUT  -p tcp --dport 80 -j ACCEPT
[root@zabbix-server html]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination  

[root@zabbix-server html]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  确定  ]

测试访问