一、firewall 方式 (centOS7.*)
二、修改 iptables 方式 (centOS6.*)
一、firewall 方式 (centOS7.*)
查看防火墻狀態(tài)
firewall-cmd --state
如果返回的是 “not running”,那么需要先開啟防火墻;
開啟防火墻
systemctl start firewalld.service
再次查看防火墻狀態(tài),發(fā)現(xiàn)已開啟!
開啟指定端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
顯示 success 表示成功
–zone=public 表示作用域?yàn)楣驳?/p>
–add-port=443/tcp 添加 tcp 協(xié)議的端口端口號為 443
–permanent 永久生效,如果沒有此參數(shù),則只能維持當(dāng)前 服 務(wù)生命周期內(nèi),重新啟動后失效;
重啟防火墻
systemctl restart firewalld.service
系統(tǒng)沒有任何提示表示成功!
重新加載防火墻
firewall-cmd --reload
顯示 success 表示成功
其他命令
#查看已開啟的端口
firewall-cmd --list-ports
#關(guān)閉指定端口
firewall-cmd --zone=public --remove-port=8080/tcp --permanent
systemctl restart firewalld.service
firewall-cmd --reload
#查看端口被哪一個進(jìn)程占用
netstat -lnpt |grep 5672
# centos7默認(rèn)沒有 netstat 命令,需要安裝 net-tools 工具:
# 安裝 net-tools
yum install -y net-tools
# 臨時(shí)關(guān)閉防火墻
systemctl stop firewalld.service
# 或者
systemctl stop firewalld
# 永久關(guān)閉防火墻(必須先臨時(shí)關(guān)閉防火墻,再執(zhí)行該命令,進(jìn)行永久關(guān)閉)
systemctl disable firewalld.service
# 或者
systemctl disable firewalld
二、修改 iptables 方式 (centOS6.*)
centOS6.* 的linux版本是自帶iptables的,所以可以直接使用該方式,centOS7 不自帶iptables的,所以要使用該方式,需要手動安裝iptables后,再使用該方式!
2.1 修改 iptables 文件
#修改iptables
?。踨oot@localhost sbin]# vi /etc/sysconfig/iptables
2.2 重啟防火墻
?。踨oot@localhost sbin]# /etc/init.d/iptables restart
三、注意事項(xiàng)
當(dāng)在 Linux 中成功開啟了某個端口,但是遠(yuǎn)程 telnet 還是無法 ping 通,是正常的!
因?yàn)?3306 端口沒有被 Linux 進(jìn)程監(jiān)聽,換句話說,就是該端口上沒有運(yùn)行任何程序?。?!
如果這時(shí),我將 Mysql 在 Linux 中啟動,并配置完成,那么遠(yuǎn)程 telnet 該端口是可以成功的!!!
編輯:黃飛
評論