linux開放關閉防火牆端口


原文:http://blog.csdn.net/fengspg/article/details/21337617

 

1) 重啟后生效 
開啟: chkconfig iptables on
關閉: chkconfig iptables off

2) 即時生效,重啟后失效
開啟: service iptables start
關閉: service iptables stop


查看iptables文件

    vim /etc/sysconfig/iptables   

redhat部分-----------

1:端口開放

/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT  

2:保存修改

/etc/rc.d/init.d/iptables save  

3: 重啟服務

/etc/rc.d/init.d/iptables restart 

4:查看端口狀態

/etc/init.d/iptables status  

 

結果如下

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:2181
2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:6379
3 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080
4 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
5 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
6 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
7 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
8 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-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 icmp-host-prohibited

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

 

5:刪除端口(2表示上面的num列)

  1. /sbin/iptables  -D INPUT 2  

centos7部分-----------

開啟端口

  1. firewall-cmd --zone=public --add-port=80/tcp --permanent  

--zone #作用域
--add-port=80/tcp  #添加端口,格式為:端口/通訊協議
--permanent   #永久生效,沒有此參數重啟后失效

重新加載防火牆

  1. firewall-cmd --reload  

檢查修改是否生效

  1. firewall-cmd --zone= public --query-port=80/tcp  

刪除某端口

  firewall-cmd --zone= public --remove-port=80/tcp   

  firewall-cmd --zone=public --remove-service=http  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM