Jump to content

6.CentOS 8 防火牆從預設firewalld更改為iptables


Jack

Recommended Posts

------------------------------------------------------
CentOS 8 防火牆從預設 firewalld 更改為 iptables
------------------------------------------------------

關閉防火牆firewalld
systemctl stop firewalld.service

systemctl disable firewalld.service


將firewalld永久關閉
systemctl mask firewalld


查看firewalld防火墙状态(关闭后显示notrunning,开启后显示running)
firewall-cmd --state


重啟
sudo reboot


安装iptables
yum -y install iptables-services


启用iptables
systemctl enable iptables


启动iptables
systemctl start iptables


重啟
sudo reboot

 

檢查 firewalld 服務是否運行
systemctl status firewalld

 

關掉selinux
vi /etc/selinux/config

SELINUX=enforcing
改為
SELINUX=disabled


保存離開
:wq

 

重啟
sudo reboot

 

 

設置防火牆iptables
cd /usr/local/bin

vi firewall.sh

將防火牆的規則複製貼上

firewall.sh的規則在這,請另開視窗觀看


保存離開
:wq

 

 

變更權限
chmod +x /usr/local/bin/firewall.sh

 

啟動防火牆
./firewall.sh

./firewall.sh start

 

開機啟動
vi /etc/rc.d/rc.local

 

將這一行貼到最底下
/usr/local/bin/firewall.sh start


保存離開
:wq

 

變更權限
chmod +x /etc/rc.d/rc.local


重啟
sudo reboot

 

確認iptables防火牆規則,有出現你的IP才可以,只有你的IP才能SSH連線
iptables -L

Edited by Jack
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...