歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> CentOS7中關閉firewall,並使用iptables管理防火牆

CentOS7中關閉firewall,並使用iptables管理防火牆

日期:2017/3/6 9:13:27   编辑:學習Linux

CentOS7中關閉firewall,並使用iptables管理防火牆


CentOS7中關閉firewall,並使用iptables管理防火牆


centOS7中默認是使用firewall管理防火牆,不習慣,所以想換成iptables:

1、關閉默認的firewall防火牆

#systemctl stop firewalld.service停止firewalld服務

#systemctl disable firewalld.service進制開機自啟動

2、開啟iptables

#yum install iptables(根據centOS7的版本和內核,有些版本已經裝過,可以跳過此命令)

#yum install iptables-services

#vim /etc/sysconfig/iptables

編輯如下(開啟了21,22,80,3306端口):

[plain]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. #sampleconfigurationforiptablesservice
  2. ##youcaneditthismanuallyorusesystem-config-firewall
  3. ##pleasedonotaskustoaddadditionalports/servicestothisdefaultconfiguration
  4. *filter
  5. :INPUTACCEPT[0:0]
  6. :FORWARDACCEPT[0:0]
  7. :OUTPUTACCEPT[0:0]
  8. -AINPUT-mstate--stateRELATED,ESTABLISHED-jACCEPT
  9. -AINPUT-picmp-jACCEPT
  10. -AINPUT-ilo-jACCEPT
  11. -AINPUT-ptcp-mstate--stateNEW-mtcp--dport21-jACCEPT
  12. -AINPUT-ptcp-mstate--stateNEW-mtcp--dport22-jACCEPT
  13. -AINPUT-ptcp-mstate--stateNEW-mtcp--dport80-jACCEPT
  14. -AINPUT-ptcp-mstate--stateNEW-mtcp--dport3306-jACCEPT
  15. -AINPUT-jREJECT--reject-withicmp-host-prohibited
  16. -AFORWARD-jREJECT--reject-withicmp-host-prohibited
  17. COMMIT

:wq保存

3、開啟服務,設置開機自啟動

#service iptables restart

#chkconfig iptables on或者systemctl enable iptables.service開機自啟

tip:如果在重啟iptables的時候,碰到讓你journalctl -xe的錯誤,使用#journalctl -xe -l來查看錯誤

一般是語法錯誤,請仔細查看iptables文件的語法。

http://xxxxxx/Linuxjc/1156037.html TechArticle

Copyright © Linux教程網 All Rights Reserved