Linux防火墙常用操作

本文详细介绍了iptables和firewalld两种Linux防火墙的管理操作,包括开启、关闭、添加规则以及端口开放的方法。对于iptables,提到了如何使用systemctl和iptables命令来控制服务状态和配置端口;而对于firewalld,讲解了使用systemctl和firewall-cmd命令进行服务管理和端口添加。此外,还展示了如何持久化防火墙配置并检查服务状态。
摘要由CSDN通过智能技术生成
1.iptables防火墙
systemctl start iptables //开启/暂停服务
systemctl stop iptables //

systemctl disable iptables //禁止/解除禁止 iptables 服务
systemctl enable iptables
service iptables status
systemctl enable iptabls.service
systemctl restart iptables.service
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3000 -j ACCEPT
systemctl start iptables.service
systemctl enable iptables
yum update iptables
yum update iptables-services
yum install -y iptables
yum install iptables-services
systemctl stop firewalld
systemctl mask firewalld

 #命令方式开放5212端口命令
 #开启5212端口接收数据
 /sbin/iptables -I INPUT -p tcp --dport 5212 -j ACCEPT

 #开启5212端口发送数据
 /sbin/iptables -I OUTPUT -p tcp --dport 5212 -j ACCEPT

 #保存配置
 /etc/rc.d/init.d/iptables save

 #重启防火墙服务
 /etc/rc.d/init.d/iptables restart

 #查看是否开启成功
 /etc/init.d/iptables status
systemctl stop firewalld.service
2.firewalld防火墙管理
systemctl restart firewalld.service
systemctl start firewalld
systemctl stop firewalld
firewall-cmd --state
firewall-cmd --zone=public --add-port=5121/tcp --permanent
firewall-cmd --zone=public --remove-port=5121/tcp --permanent
# --zone 作用域
# --add-port=5121/tcp 添加端口,格式为:端口/通讯协议
# --permanent 永久生效,没有此参数重启后失效
firewall-cmd --reload
 #查看开放的端口列表
firewall-cmd --list-ports
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值