前言
主要讲解:
防火墙的开启与关闭等常用命令
firewall-cmd配置端口等
Centos7这个版本的防火墙使用的是firewall,在这之前的版本Centos 6以下都是使用iptables
现在多数版本都是使用的是firewall,如果你的iptables执行不了,可测试一下firewall命令参数
1. iptables防火墙常用命令
比如我使用的是ubuntu系统下的
使用iptables命令,查询其参数

由于博主这个命令已经没有了
以下命令都执行不了, 但如果你是centos6以下,也可以测试以下命令
回顾该命令的参数:
-
查看防火墙状态:
service iptables status -
停止防火墙:
service iptables stop -
启动防火墙:
service iptables start -
重启防火墙:
service iptables restart -
永久关闭防火墙:
chkconfig iptables off -
永久关闭后重启:
chkconfig iptables on
开启端口号
在配置文件中直接打开某个端口并且启动后,重新打开防火墙的一系列命令为:
通过vi 或者vim 或者gedit打开这个文件/etc/sysconfig/iptables
在文后加入以下代码
-A INPUT -m state --state NEW -m tcp -p tcp --dport 端口号 -j ACCEPT
保存退出后重启防火墙service iptables restart
2. firewall防火墙常用命令
这些命令都可在我的电脑下执行
设置开启启动防火墙:systemctl enable firewalld.service

设置开机禁止防火墙:systemctl disable firewalld.service

启动防火墙:systemctl start firewalld
静止防火墙:systemctl stop firewalld

查看防火墙的具体信息,以及检查其状态:systemctl status firewalld

2.1 firewall-cmd命令
查看防火墙规则:firewall-cmd --list-all


查看防火墙状态:firewall-cmd --state


重新加载配置:firewall-cmd --reload


2.2 打开关闭端口
打开防火墙端口号:firewall-cmd --zone=public --add-port=8080/tcp --permanent

关闭防火墙端口号:firewall-cmd --zone=public --remove-port=9200/tcp --permanent

具体参数讲解
--permanent:设置为永久
--add-port:添加的端口,格式为端口/通讯协议
--zone :作用域
添加完端口号后记得重启以下,才能看见端口号firewall-cmd --reload
查看开放的端口:firewall-cmd --list-ports

本文介绍了CentOS系统中iptables和firewall防火墙的常用命令,包括查看状态、开启关闭、端口管理等操作。对于CentOS7及以上版本,重点讲述了firewall-cmd的使用,如添加、移除端口,并强调了规则的持久化设置。此外,还提供了开启和关闭防火墙的系统服务命令。
4203

被折叠的 条评论
为什么被折叠?



