centos7离线安装iptables【详细】

一、关闭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、配置正常完成安装

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值