CentOS7使用iptables防火牆開放端口


背景:在CentOS上面安裝了mysql、svn、tomcat等軟件,發現訪問不了,用telnet命令查看端口,發現都不通:

telnet IP 端口

CentOS7 默認使用firewalld防火牆,如果想換回iptables防火牆,可關閉firewalld並安裝iptables。

1、關閉firewall:

停止firewall:

systemctl stop firewalld.service

禁止firewall開機啟動

systemctl disable firewalld.service

查看默認防火牆狀態(關閉后顯示not running,開啟后顯示running)

firewall-cmd --state

2.安裝iptables-services

yum install iptables-services

3.修改防火牆配置文件

vi /etc/sysconfig/iptables 

添加端口80、8080、3306、3690端口:

這里寫圖片描述

注意:添加在端口22上面或者下面,不要放在最后,不然不起作用。另外,mac上面insert輸入直接按字母”i”鍵即可。

esc :wq! 退出保存修改。

4.重啟防火牆使配置生效

systemctl restart iptables.service

設置防火牆開機啟動:

systemctl enable iptables.service

 

再次嘗試連接,成功了!

5.注意

客戶端連接不了可能原因有多種,比如:

1.服務器端服務未啟動

2.軟件本身未開通用戶訪問權限
比如

a.mysql需要針對用戶開放權限:

mysql授權:

grant all privileges on dbName.* to dbuser@'%' identified by 'dbpassword' with grant option;
flush privileges;

切記:一定要刷新權限。

b.svn需要事先建好倉庫並配置用戶、權限等信息等。

3.服務器端口被防火牆封掉。

請先排除1、2可能,綜合處理訪問權限問題。


https://blog.csdn.net/irokay/article/details/72717132?utm_source=copy


免責聲明!

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



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