linux系统防火墙相关


由于Centos7开始,还有部分redhot的版本,默认使用firewalld管理防火墙,则使用iptablse开启防火墙时会报错:
Failed to start IPv4 firewall with iptables.
解决办法:使用firewalld,或者关闭firewalld然后安装iptablses,推荐直接使用firewalld,配置端口更加简单快捷

A:直接使用firewalld

  • 开启

systemctl start/enable firewalld //开启firewalld

前置条件1:是没有关闭firewall使用iptables配置过防火墙,否则得先切换会firewalld,具体方法如下:

systemctl stop iptables //关闭iptables
systemctl mask iptables //屏蔽iptables

systemctl unmask firewalld //解除对firewalld的屏蔽

前置条件2:如果开启报错

Unit firewalld.service could not be found.

则重新安装firewalld:

yum install firewalld

至此就可以直接使用开启命令进行开启了

  • 查看状态

systemctl status firewalld

  • 添加开启端口8088
firewall-cmd --zone=public --add-port=8088/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
  • 添加开启端口段1000–2000
firewall-cmd --zone=public --add-port=1000-2000/tcp --permanent
  • 重新加载
systemctl restart firewalld
  • 关闭
systemctl stop/disable firewalld
  • 查看配置的端口列表
firewall-cmd --list-ports
  • 查看端口是否开启
firewall-cmd --zone=public --query-port=80/tcp
  • 删除端口
firewall-cmd --zone=public --remove-port=80/tcp --permanent(--permanent永久生效,没有此参数重启后失效)

B:iptables方式

1:当默认就为iptables管理防火墙的

  • 直接编辑

vi /etc/sysconfig/iptables

  • 增加一个8080端口

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

  • 退出保存

  • 重启linux防火墙服务即可

/etc/init.d/iptables restart

2:默认为firewalld需要使用iptables的

  • 安装iptables-service

yum install iptables-services

  • 关闭和屏蔽firewalld

systemctl stop firewalld //关闭firewalld
systemctl mask firewalld //屏蔽firewalld

  • 设置开机启动

systemctl enable iptables
-使用上面方式进行配置

service iptables stop 关闭防火墙
service iptables start 开启防火墙
service iptables restart 重启防火墙
service iptables status 查看状态
yum remove iptables 卸载

开启一个端口的顺序:

首先保证防火墙开启->通过查看防火墙状态命令
添加端口->添加端口命令
重新载入->重新载入命令

CentOS7中执行

service iptables start/sto
会报错Failed to start iptables.service: Unit iptables.service failed to load: No such file or directory.
由于CentOS7开始 默认使用firewalld管理防火墙 上面解决方法

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值