linux防火墻常用操作,包含了基本的防火墻啟動(dòng)/停止、端口開放設(shè)置、端口出入站設(shè)置等相關(guān)功能姜钳。由于Linux各個(gè)發(fā)行版使用的防火墻軟件并不相同,特此整理該文檔幫助大家能夠進(jìn)行速查凤覆。
防火墻軟件對(duì)照
以防火墻軟件為索引似扔,使用了該防火墻軟件的Linux發(fā)行版如下清單所示:
- firewall-cmd租冠,適用于centos7搪花。
- iptables遏片,適用于centos6嘹害。
一般性前置條件
一般對(duì)防火墻進(jìn)行操作時(shí),需要使用具備系統(tǒng)管理者的身份執(zhí)行指令吮便。本文檔所有操作命令示例均按已經(jīng)獲得系統(tǒng)管理者權(quán)限為前提笔呀。另外本文所有指令均已80端口為樣例。
firewall-cmd軟件
- 查看防火墻狀態(tài)
firewall-cmd --state
- 開啟防火墻
systemctl start firewalld
- 關(guān)閉防火墻
systemctl stop firewalld
- 設(shè)置開機(jī)啟動(dòng)
systemctl enable firewalld
- 禁用開機(jī)啟動(dòng)
sytemctl disable firewalld
- 重啟防火墻
firewall-cmd --reload
- 開放防火墻端口
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
- 關(guān)閉防火墻端口
firewall-cmd --permanent --remove-port=80/tcp
firewall-cmd --reload
- 查看防火墻規(guī)則
firewall-cmd --list-all
iptables軟件
- 查看防火墻狀態(tài)
firewall-cmd --state
- 開啟防火墻
service iptables start
- 關(guān)閉防火墻
service iptables stop
- 設(shè)置開機(jī)啟動(dòng)
chkconfig iptables on
- 禁用開機(jī)啟動(dòng)
chkconfig iptables off
- 重啟防火墻
service iptables restartd
- 開放防火墻端口
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/init.d/iptables save
service iptables restart
- 關(guān)閉防火墻端口
/sbin/iptables -I INPUT -p tcp --dport 端口號(hào) -j DROP
/etc/init.d/iptables save
service iptables restart
- 查看防火墻規(guī)則
/etc/init.d/iptables status
版權(quán)聲明髓需,本文首發(fā)于 數(shù)字魔盒 https://www.dm2box.com/ 歡迎轉(zhuǎn)載许师。