Cent OS防火牆配置端口開放


CentOS 6內置的防火牆為iptables,Cent OS7,內置的防火牆則是firewalld

iptables 防火牆設置

1.打開/關閉/重啟防火牆

#開啟防火牆(重啟后永久生效):
chkconfig iptables on
 
#關閉防火牆(重啟后永久生效):
chkconfig iptables off
 
#開啟防火牆(即時生效,重啟后失效):
service iptables start
 
#關閉防火牆(即時生效,重啟后失效):
service iptables stop
 
#重啟防火牆:
service iptables restartd

2.查看防火牆打開的端口
此處以開放8080端口為例:

(1)開放端口

iptables -A INPUT -p tcp --dport 1024 -j ACCEPT

(2)保存並生效

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

4.開放指定范圍的端口

例如開放1024-10240之間的所有端口:

iptables -A INPUT -p tcp --dport 1024:10240 -j ACCEPT

firewalld防火牆設置

1.查看防火牆狀態

systemctl status firewalld

此處如果提示firewalld.service could not be found.則說明你的系統沒有裝防火牆,則不需要設置。

2.開放指定端口

此處以開放1024端口為例:

firewall-cmd --zone=public --add-port=1024/tcp --permanent

–permanent參數表示永久生效,沒有此參數重啟后失效。

3.重啟防火牆

#重啟firewall
firewall-cmd --reload 

#停止firewall
systemctl stop firewalld.service 

 #禁止firewall開機啟動
systemctl disable firewalld.service

#重啟firewall
firewall-cmd --reload 

 #停止firewall
systemctl stop firewalld.service

 #禁止firewall開機啟動
systemctl disable firewalld.service

#查看默認防火牆狀態(關閉后顯示notrunning,開啟后顯示running)
1
firewall-cmd --state 

#查看默認防火牆狀態(關閉后顯示notrunning,開啟后顯示running)
firewall-cmd --state


免責聲明!

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



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