CentOS6、CentOS7 防火牆開放、關閉端口


當我們在CentOS服務器中裝了一些開發環境(如 tomcat、mysql、nginx 等...)時,希望能從外界訪問,就需要配置防火牆對指定端口開放。

CentOS 6.5

1.開放指定端口
/sbin/iptables -I INPUT -p tcp --dport 端口號 -j ACCEPT   //寫入修改
/etc/init.d/iptables save                                       //保存修改
service iptables restart                                               //重啟防火牆,修改生效
2.關閉指定端口
/sbin/iptables -I INPUT -p tcp --dport 端口號 -j DROP       //寫入修改
/etc/init.d/iptables save                                        //保存修改
service iptables restart                                             //重啟防火牆,修改生效
3.查看端口狀態
/etc/init.d/iptables status


CentOS 7
1.防火牆操作
啟動: systemctl start firewalld
查看狀態: systemctl status firewalld 
停止: systemctl disable firewalld
禁用: systemctl stop firewalld
2.開放指定端口
firewall-cmd --zone=public --add-port=80/tcp --permanent   //開放端口
firewall-cmd --reload                                                                   //重新載入,使其生效
3.關閉指定端口
firewall-cmd --zone=public --remove-port=80/tcp --permanent            //關閉端口
firewall-cmd --reload                                                                   //重新載入,使其生效
4.查看端口狀態
firewall-cmd --zone=public --query-port=80/tcp                            //查看端口狀態


免責聲明!

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



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