一、关闭centos自带防火墙
1、检查系统防火墙状态
[root@localhost~]#systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Wed 2023-03-01 15:40:29 CST; 5 days ago
Docs: man:firewalld(1)
Main PID: 783 (code=exited, status=0/SUCCESS)
说明系统防火墙已关闭
如果Active: active,说明防火墙是开启的,执行:
[root@localhost~]#systemctl stop firewalld
2、禁用系统防火墙
[root@localhost~]#systemctl mask firewalld
[root@localhost~]#systemctl status firewalld
● firewalld.service
Loaded: masked (/dev/null; bad)
Active: inactive (dead) since Wed 2023-03-01 15:40:29 CST; 5 days ago
Main PID: 783 (code=exited, status=0/SUCCESS)
二、iptables安装
1、上传iptables安装包
iptables-1.4.21-35.el7.x86_64.rpm
iptables-services-1.4.21-35.el7.x86_64.rpm
2、检查主机是否安装有旧iptables服务
[root@localhost~]#rpm -qa|grep iptables
iptables-1.4.21-35.el7.x86_64
如果存在旧服务,要先卸载
[root@localhost~]#rpm -e --nodeps iptables-1.4.21-35.el7.x86_64
3、安装iptables
[root@localhost~]#rpm -Uvh iptables-1.4.21-35.el7.x86_64.rpm
[root@localhost~]#rpm -Uvh iptables-services-1.4.21-35.el7.x86_64.rpm
4、查看iptables是否安装成功
[root@localhost~]#systemctl status iptables
● iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)
Active: inactive (dead)
5、使能iptables开机自启动
[root@localhost~]#systemctl enable iptables
[root@localhost~]#systemctl start iptables
6、配置iptables相应规则
[root@localhost~]#vim /etc/sysconfig/iptables
7、配置完成后重启iptables
[root@localhost~]#systemctl restart iptables
8、查看iptables状态是否正常
[root@localhost~]#systemctl status iptables
● iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
Active: active (exited) since Tue 2023-03-07 10:07:46 CST; 59s ago
Process: 6195 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)
Process: 6213 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)
Main PID: 6213 (code=exited, status=0/SUCCESS)
9、配置正常完成安装