linux系统 centos中iptables使用教程

本文详细介绍在CentOS系统中如何使用iptables与firewall服务进行防火墙管理,包括查看、启动、停止、重启防火墙,以及如何永久关闭或开启防火墙。此外,还介绍了如何通过编辑配置文件和使用命令行来开放特定端口的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

linux系统 centos中iptables与firewall使用教程

1、简单命令介绍

//查看防火墙状态

 service iptables status
# 启动iptables防火墙 
 service iptables start 
 #停止iptables防火墙 
service iptables stop 
  #重启iptables防火墙 ,并加载配置文件
  service iptables restart 
 #永久iptables关闭防火墙 
 chkconfig iptables off 
#永久关闭iptables后重启 
 chkconfig iptables on

2.开启防火墙其他端口,示例如下:

#使用vim指令打开iptables的配置文件
 vim /etc/sysconfig/iptables
 #追加下面文字到iptables配置文件中如图所示
 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT

在这里插入图片描述

#保存iptables文件并退出
!wq
#执行如下指令重启iptables防火墙
[root@host-10-19-83-74 ~]#   service iptables restart

2.firewall
查询放行的端口

 firewall-cmd --zone=public --list-ports

新增放行端口(比如8080):

firewall-cmd --zone=public --add-port=8080/tcp --permanent

重载配置文件

firewall-cmd --reload

firewalld的基本使用

启动: systemctl start firewalld

查看状态: systemctl status firewalld 

停止: systemctl disable firewalld

禁用: systemctl stop firewalld
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值