linux yum安装iptables,如何在CentOS 7上安装 Iptables

从CentOS 7开始,FirewallD将替换iptables成为默认的防火墙管理工具。

FirewallD是一个完整的防火墙解决方案,可以使用名为firewall-cmd的命令行实用程序进行控制。 如果您对Iptables命令行语法更熟悉,那么您可以禁用FirewallD并返回到经典的iptables设置。

本教程将向您展示如何禁用FirewallD服务并安装iptables。

禁用FirewallD

禁用FirewallD需要执行以下步骤:

01、键入以下命令以停止FirewallD服务:

sudo systemctl stop firewalld

02、禁用FirewallD服务在系统启动时自动启动:

sudo systemctl disable firewalld

03、屏蔽FirewallD服务以防止其他服务启动它:

sudo systemctl mask --now firewalld

安装并启用Iptables

执行以下步骤在CentOS 7系统上安装Iptables:

01、运行以下命令从CentOS存储库安装iptables-service软件包:

sudo yum install iptables-services

02、软件包安装完成后启动Iptables服务:

sudo systemctl start iptables

sudo systemctl start iptables6

03、设置Iptables服务为系统启动时服务默认启动:

sudo systemctl enable iptables

sudo systemctl enable iptables6

04、检查Iptables服务状态:

sudo systemctl status iptables

sudo systemctl status iptables6

05、通过以下命令检查iptables规则:

sudo iptables -nvL

sudo iptables6 -nvL

默认情况下,仅打开SSH端口22。 输出应该如下所示:

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)

pkts bytes target prot opt in out source destination

5400 6736K ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED

0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0

2 148 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0

3 180 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22

0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)

pkts bytes target prot opt in out source destination

0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 4298 packets, 295K bytes)

pkts bytes target prot opt in out source destination

此时,您已成功启用iptables服务,您可以开始构建防火墙。 重新启动后更改将保持不变。

总结

在本教程中,您学习了如何禁用FirewallD服务并安装iptables。

如果您有任何问题或意见,请在下面留言。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值