問題: 進(jìn)行iptables防火墻操作時(shí)梁肿,發(fā)現(xiàn)在/etc/sysconfig/下找不到iptables文件
解決方法:CentOS7對(duì)比CentOS6防火墻升級(jí)了膀懈,默認(rèn)防火墻為firewalld枚尼;CentOS7要切換為iptables防火墻挽鞠,應(yīng)先stop默認(rèn)的firewalld杆逗,然后安裝iptables服務(wù)
一午乓、firewald 介紹和常用命令
firewald 配置
The configuration for firewalld is stored in various XML files in /usr/lib/firewalld/ and? /etc/firewalld/.
防火墻的配置在/usr/lib/firewalld/?系統(tǒng)配置目錄 &?/etc/firewalld/ 用戶配置目錄中
其中/usr/lib/firewalld/services 存放定義好的網(wǎng)絡(luò)服務(wù)和端口參數(shù)磅摹,系統(tǒng)參數(shù)滋迈,不能修改
注意:以下firewalld 的操作只有重啟之后才有效:service firewalld restart 重啟
firewall常用命令
啟動(dòng): systemctl start firewalld
關(guān)閉: systemctl stop firewalld
查看狀態(tài): systemctl status firewalld?
開機(jī)禁用? : systemctl disable firewalld
開機(jī)啟用? :?systemctl enable firewalld
systemctl 是CentOS7之后版本的服務(wù)管理工具,它融合之前service和chkconfig的功能
啟動(dòng)一個(gè)服務(wù):systemctl start firewalld.service
關(guān)閉一個(gè)服務(wù):systemctl stop firewalld.service
重啟一個(gè)服務(wù):systemctl restart firewalld.service
顯示一個(gè)服務(wù)的狀態(tài):systemctl status firewalld.service
在開機(jī)時(shí)啟用一個(gè)服務(wù):systemctl enable firewalld.service
在開機(jī)時(shí)禁用一個(gè)服務(wù):systemctl disable firewalld.service
查看服務(wù)是否開機(jī)啟動(dòng):systemctl is-enabled? firewalld.service
查看已啟動(dòng)的服務(wù)列表:systemctl list-unit-files|grep? enabled
查看啟動(dòng)失敗的服務(wù)列表:systemctl? --failed
查看firewall的狀態(tài)
firewall-cmd? --state
查看防火墻規(guī)則
firewall-cmd? --list-all
二户誓、CentOS切換為iptables防火墻
step1: 關(guān)閉firewall
切換root身份? su -饼灿,輸入root密碼
systemctl stop firewalld? 關(guān)閉firewall
systemctl disable firewalld.service? 禁止firewall開機(jī)啟動(dòng)
step2: 安裝iptables防火墻
yum installi ptables-services 安裝
step3: 編輯iptables防火墻配置
vim? /etc/sysconfig/iptables? 編輯防火墻配置文件
打開后,可看到防火墻中默認(rèn)的規(guī)則
若你需要修改的話帝美,按 i 進(jìn)入Inter編輯模板碍彭,進(jìn)行重新定義規(guī)則
按Esc鍵退出編輯, 按 :wq 保存并退出
step4:開啟iptables
service iptables start? 開啟
systemctl enable iptables.service 設(shè)置防火墻開機(jī)啟動(dòng)
service iptables status 查看狀態(tài)
iptables常用命令
啟動(dòng): service iptables start
關(guān)閉: service iptables stop
重啟:service iptables restart
查看狀態(tài): service iptables status
開機(jī)禁用? : chkconfig iptables off
開機(jī)啟用? :?chkconfig iptables on
查看防火墻是否開機(jī)啟動(dòng):chkconfig iptables --list
參考鏈接:
https://blog.csdn.net/iamzhangyouzhi/article/details/41978537
https://blog.csdn.net/a837201942/article/details/76690916