iptables
CentOS 7 以下的系統(tǒng)版本防火墻均使用iptables,所以要進(jìn)行端口操作,請需要輸入iptables命令開放端口(80為例):
關(guān)閉端口(80為例):
/sbin/iptables-IINPUT-ptcp--dport80-jDROP保存更改:
/etc/rc.d/init.d/iptablessave查看開放端口:
/etc/init.d/iptablesstatusfirewallCentOS 7 及以上的系統(tǒng)版本防火墻均使用firewall,所以要進(jìn)行端口操作,請需要輸入firewall命令1.查看已經(jīng)開放的端口:
firewall-cmd--list-ports2.添加端口(80端口為例):
firewall-cmd--zone=public--add-port=80/tcp--permanent3.重新載入:
firewall-cmd--reload4.檢查端口:
firewall-cmd--zone=public--query-port=80/tcp5.關(guān)閉端口(80為例):
firewall-cmd--zone=public--remove-port=80/tcp--permanent6.重啟防火墻:
firewall-cmd--reload#重啟firewall systemctlstopfirewalld.service#停止firewall systemctldisablefirewalld.service#禁止firewall開機(jī)啟動 firewall-cmd--state#查看默認(rèn)防火墻狀態(tài)(關(guān)閉后顯示notrunning,開啟后顯示running)7.命令含義:
–zone#作用域 –add-port=80/tcp#添加端口,格式為:端口/通訊協(xié)議 –permanent#永久生效,沒有此參數(shù)重啟后失效關(guān)閉firewall,安裝iptablesCentOS 7默認(rèn)使用的是firewall作為防火墻,使用iptables必須重新設(shè)置一下1.關(guān)閉防火墻,禁止開啟啟動
systemctlstopfirewalld.service systemctldisablefirewalld.service2.安裝 iptables service
yum-yinstalliptables-services3.后續(xù)即可使用iptable命令操作來管理防火墻