-
2022-04-15 14:27:52
我们在服务器在安装Mysql、Tomcat 等需要端口的服务时,需要对防火墙进行一些操作,以下命令经常会被用到
1、查看防火墙的状态 (dead代表关闭 running代表已经开启)
systemctl status firewalld
2、查看防火墙所有开放的端口
firewall-cmd --list-ports
3、开启防火墙
systemctl start firewalld
4、开放指定端口号(同时注意要在云服务器开放端口)
firewall-cmd --permanent --add-port=80/tcp
5、重启防火墙
firewall-cmd --reload
6、 查询指定端口是否有进程守护,用如下命令grep对应端口(以80端口为例)
netstat -nalp|grep 80
7、关闭防火墙
systemctl disable firewalld
更多相关内容 -
Linux防火墙配置命令
2021-08-14 17:45:50目录Linux系统防火墙配置命令一、防火墙开启、关闭、禁用二、配置防火墙端口注意事项: Linux系统防火墙配置命令 在Linux系统中进行Java项目部署时需要经常对防火墙进行配置,有一些基本命令没有完全记住,每一次都...
Linux系统防火墙配置命令
在Linux系统中进行Java项目部署时需要经常对防火墙进行配置,有一些基本命令没有完全记住,每一次都要到网络上查阅相关资料,在此将这些常用命令记录下来,方便在项目部署时查阅和平时学习使用。
一、防火墙开启、关闭、禁用
1、设置开机自动启用防火墙
systemctl enable firewalld.service
2、设置开机不需要自动启动防火墙
systemctl disable firewalld.service
3、启动防火墙
systemctl start firewalld
4、关闭防火墙
systemctl stop firewalld
5、检查当前防火墙的状态
systemctl status firewalld
二、配置防火墙端口
1、查看防火墙状态
firewall-cmd --state
2、重新启动防火墙
firewall-cmd --reload
3、查看防火墙开放的端口
firewall-cmd --list-ports
4、检查某个端口是否开放
firewall-cmd --query-port 端口号/tcp
5、开启防火墙指定端口
firewall-cmd --zone=public --add-port=端口号/tcp --permanent
6、移除指定端口
firewall-cmd --zone=public --remove-port=端口号/tcp --permanent
关于防火墙操作的解释:
–zone
=> 作用域
–add-port=端口号/tcp
=> 添加端口,格式为:端口/通讯协议
–remove-port=端口号/tcp
=> 移除端口,格式为:端口/通讯协议
–permanent
=> 永久生效,没有此参数重启后失效注意事项:
在执行添加端口命令后,必须再执行一遍重新启动防火墙命令后开放的端口才会生效
-
Linux 中防火墙命令
2022-03-31 01:04:56Linux 中防火墙命令 1.安装firewall 在CentOS 7中防火墙已经由firewalld来管理,Centos7默认安装了firewalld,没有安装的可以用yum 命令安装,与iptables区别不小 yum install firewalld firewalld-config 2.查看...Linux 中防火墙命令
1.安装firewall
在CentOS 7中防火墙已经由firewalld来管理,Centos7默认安装了firewalld,没有安装的可以用yum 命令安装,与iptables区别不小
yum install firewalld firewalld-config
2.查看防火墙状态
[root@localhost /]# systemctl status firewalld //或者 firewall-cmd --state ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) //inactive表示为关闭状态 Docs: man:firewalld(1)
3.启动防火墙
[root@localhost /]# systemctl start firewalld.service
4.重启防火墙
firewall-cmd --reload 或者 service firewalld restart
5.防火墙开放3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent //--permanent永久生效,没有此参数防火墙重启便失
6防火墙关闭开放的3306端口
firewall-cmd --zone=public --remove-port=3306/tcp --permanent
7.禁用防火墙
systemctl stop firewalld
8.设置开机启动
systemctl enable firewalld
9.停止并禁用开机启动
sytemctl disable firewalld
10.查看端口列表
firewall-cmd --permanent --list-all
-
Linux关闭防火墙命令
2019-05-27 14:59:55一、下面是red hat/CentOs7关闭防火墙的命令! 1:查看防火状态 systemctl status firewalld service iptablesstatus 2:暂时关闭防火墙 systemctl stop firewalld service iptablesstop 3:永久关闭防火墙 ...一、下面是red hat/CentOs7关闭防火墙的命令!
1:查看防火状态
systemctl status firewalld
service iptables status
2:暂时关闭防火墙
systemctl stop firewalld
service iptables stop
3:永久关闭防火墙
systemctl disable firewalld
chkconfig iptables off
4:重启防火墙
systemctl enable firewalld
service iptables restart
5:永久关闭后重启
//暂时还没有试过
chkconfig iptables on
二、firewalld
Centos7默认安装了firewalld,如果没有安装的话,可以使用 yum install firewalld firewalld-config进行安装。
1.启动防火墙
systemctl start firewalld
2.禁用防火墙
systemctl stop firewalld
3.设置开机启动
systemctl enable firewalld
4.停止并禁用开机启动
sytemctl disable firewalld
5.重启防火墙
firewall-cmd --reload
6.查看状态
systemctl status firewalld或者 firewall-cmd --state
7.查看版本
firewall-cmd --version
8.查看帮助
firewall-cmd --help
9.查看区域信息
firewall-cmd --get-active-zones
10.查看指定接口所属区域信息
firewall-cmd --get-zone-of-interface=eth0
11.拒绝所有包
firewall-cmd --panic-on
12.取消拒绝状态
firewall-cmd --panic-off
13.查看是否拒绝
firewall-cmd --query-panic
14.将接口添加到区域(默认接口都在public)
firewall-cmd --zone=public --add-interface=eth0(永久生效再加上 --permanent 然后reload防火墙)
15.设置默认接口区域
firewall-cmd --set-default-zone=public(立即生效,无需重启)
16.更新防火墙规则
firewall-cmd --reload或firewall-cmd --complete-reload(两者的区别就是第一个无需断开连接,就是firewalld特性之一动态 添加规则,第二个需要断开连接,类似重启服务)
17.查看指定区域所有打开的端口
firewall-cmd --zone=public --list-ports
18.在指定区域打开端口(记得重启防火墙)
firewall-cmd --zone=public --add-port=80/tcp(永久生效再加上 --permanent)
说明:
–zone 作用域
–add-port=8080/tcp 添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效补充:
CentOS 7 下使用 Firewall
在 CentOS 7 中,引入了一个新的服务,Firewalld,下面一张图,让大家明确的了解 Firewall 与 iptables 之间的关系与区别。
安装它,只需
# yum install firewalld
如果需要图形界面的话,则再安装
# yum install firewall-config
一、介绍
防火墙守护 firewalld 服务引入了一个信任级别的概念来管理与之相关联的连接与接口。它支持 ipv4 与 ipv6,并支持网桥,采用 firewall-cmd (command) 或 firewall-config (gui) 来动态的管理 kernel netfilter 的临时或永久的接口规则,并实时生效而无需重启服务。
zone
Firewall 能将不同的网络连接归类到不同的信任级别,Zone 提供了以下几个级别
- drop: 丢弃所有进入的包,而不给出任何响应
- block: 拒绝所有外部发起的连接,允许内部发起的连接
- public: 允许指定的进入连接
- external: 同上,对伪装的进入连接,一般用于路由转发
- dmz: 允许受限制的进入连接
- work: 允许受信任的计算机被限制的进入连接,类似 workgroup
- home: 同上,类似 homegroup
- internal: 同上,范围针对所有互联网用户
- trusted: 信任所有连接
过滤规则
- source: 根据源地址过滤
- interface: 根据网卡过滤
- service: 根据服务名过滤
- port: 根据端口过滤
- icmp-block: icmp 报文过滤,按照 icmp 类型配置
- masquerade: ip 地址伪装
- forward-port: 端口转发
- rule: 自定义规则
其中,过滤规则的优先级遵循如下顺序
- source
- interface
- firewalld.conf
二、使用方法
# systemctl start firewalld # 启动, # systemctl enable firewalld # 开机启动 # systemctl stop firewalld # 关闭 # systemctl disable firewalld # 取消开机启动
具体的规则管理,可以使用
firewall-cmd
,具体的使用方法可以$ firewall-cmd --help --zone=NAME # 指定 zone --permanent # 永久修改,--reload 后生效 --timeout=seconds # 持续效果,到期后自动移除,用于调试,不能与 --permanent 同时使用
1. 查看规则
查看运行状态
$ firewall-cmd --state
查看已被激活的 Zone 信息
$ firewall-cmd --get-active-zones public interfaces: eth0 eth1
查看指定接口的 Zone 信息
$ firewall-cmd --get-zone-of-interface=eth0 public
查看指定级别的接口
$ firewall-cmd --zone=public --list-interfaces eth0
查看指定级别的所有信息,譬如 public
$ firewall-cmd --zone=public --list-all public (default, active) interfaces: eth0 sources: services: dhcpv6-client http ssh ports: masquerade: no forward-ports: icmp-blocks: rich rules:
查看所有级别被允许的信息
$ firewall-cmd --get-service
查看重启后所有 Zones 级别中被允许的服务,即永久放行的服务
$ firewall-cmd --get-service --permanent
2. 管理规则
# firewall-cmd --panic-on # 丢弃 # firewall-cmd --panic-off # 取消丢弃 # firewall-cmd --query-panic # 查看丢弃状态 # firewall-cmd --reload # 更新规则,不重启服务 # firewall-cmd --complete-reload # 更新规则,重启服务
添加某接口至某信任等级,譬如添加 eth0 至 public,永久修改
# firewall-cmd --zone=public --add-interface=eth0 --permanent
设置 public 为默认的信任级别
# firewall-cmd --set-default-zone=public
a. 管理端口
列出 dmz 级别的被允许的进入端口
# firewall-cmd --zone=dmz --list-ports
允许 tcp 端口 8080 至 dmz 级别
# firewall-cmd --zone=dmz --add-port=8080/tcp
允许某范围的 udp 端口至 public 级别,并永久生效
# firewall-cmd --zone=public --add-port=5060-5059/udp --permanent
b. 网卡接口
列出 public zone 所有网卡
# firewall-cmd --zone=public --list-interfaces
将 eth0 添加至 public zone,永久
# firewall-cmd --zone=public --permanent --add-interface=eth0
eth0 存在与 public zone,将该网卡添加至 work zone,并将之从 public zone 中删除
# firewall-cmd --zone=work --permanent --change-interface=eth0
删除 public zone 中的 eth0,永久
# firewall-cmd --zone=public --permanent --remove-interface=eth0
c. 管理服务
添加 smtp 服务至 work zone
# firewall-cmd --zone=work --add-service=smtp
移除 work zone 中的 smtp 服务
# firewall-cmd --zone=work --remove-service=smtp
d. 配置 external zone 中的 ip 地址伪装
查看
# firewall-cmd --zone=external --query-masquerade
打开伪装
# firewall-cmd --zone=external --add-masquerade
关闭伪装
# firewall-cmd --zone=external --remove-masquerade
e. 配置 public zone 的端口转发
要打开端口转发,则需要先
# firewall-cmd --zone=public --add-masquerade
然后转发 tcp 22 端口至 3753
# firewall-cmd --zone=public --add-forward-port=port=22:proto=tcp:toport=3753
转发 22 端口数据至另一个 ip 的相同端口上
# firewall-cmd --zone=public --add-forward-port=port=22:proto=tcp:toaddr=192.168.1.100
转发 22 端口数据至另一 ip 的 2055 端口上
# firewall-cmd --zone=public --add-forward-port=port=22:proto=tcp:toport=2055:toaddr=192.168.1.100
f. 配置 public zone 的 icmp
查看所有支持的 icmp 类型
# firewall-cmd --get-icmptypes destination-unreachable echo-reply echo-request parameter-problem redirect router-advertisement router-solicitation source-quench time-exceeded
列出
# firewall-cmd --zone=public --list-icmp-blocks
添加 echo-request 屏蔽
# firewall-cmd --zone=public --add-icmp-block=echo-request [--timeout=seconds]
移除 echo-reply 屏蔽
# firewall-cmd --zone=public --remove-icmp-block=echo-reply
g. IP 封禁
# firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='222.222.222.222' reject"
当然,我们仍然可以通过 ipset 来封禁 ip
封禁 ip
# firewall-cmd --permanent --zone=public --new-ipset=blacklist --type=hash:ip # firewall-cmd --permanent --zone=public --ipset=blacklist --add-entry=222.222.222.222
封禁网段
# firewall-cmd --permanent --zone=public --new-ipset=blacklist --type=hash:net # firewall-cmd --permanent --zone=public --ipset=blacklist --add-entry=222.222.222.0/24
导入 ipset 的 blacklist 规则
# firewall-cmd --permanent --zone=public --new-ipset-from-file=/path/blacklist.xml
如果已经存 blacklist,则需要先删除
# firewall-cmd --get-ipsets blacklist # firewall-cmd --permanent --zone=public --delete-ipset=blacklist
然后封禁 blacklist
# firewall-cmd --permanent --zone=public --add-rich-rule='rule source ipset=blacklist drop'
重新载入以生效
# firewall-cmd --reload
查看 blacklist
# firewall-cmd --ipset=blacklist --get-entries
以上都是一些常用方法,更多高级方法,请参考:
-
linux关闭防火墙命令
2021-05-15 16:18:28在linux中防火墙的开启和关闭是可以...1.Linux关闭防火墙命令1) 永久性生效,重启后不会复原开启:chkconfig iptables on关闭:chkconfig iptables off2) 即时生效,重启后复原开启:service iptables start关闭:s... -
Linux防火墙命令大全
2018-09-02 07:33:20原:Linux之 linux7防火墙基本使用及详解_张冲andy的博客-CSDN博客 1、firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld 停止:systemctl stop firewalld 禁用:... -
Linux 防火墙常用命令
2022-03-27 17:12:46一、下面是red hat/CentOs7关闭防火墙的命令! 1:查看防火状态 systemctl status firewalld service iptablesstatus 2:暂时关闭防火墙 systemctl stop firewalld service iptablesstop 3:永久关闭防火墙 ... -
Linux防火墙命令
2021-03-22 13:46:33文章目录Linux防火墙常用命令一、centos7二、centos6 Linux防火墙常用命令 centos7防火墙默认使用的是firewalld centos6防火墙默认使用的是iptables 一、centos7 1、开放端口的命令格式:firewall-cmd --zone=... -
Linux中防火墙命令笔记
2021-05-16 03:58:01#启动 systemctl start firewalld#开机启动 systemctl enable firewalld#停止 systemctl stop firewalld#禁止开机关闭 systemctl disable firewalld#查看状态 systemctl status firewalld#防火墙控制台firewall-cmd#... -
Linux关闭/开启防火墙命令
2021-05-12 15:44:06Linux还是比较常用的,于是我研究了一下Linux关闭防火墙命令,在这里拿出来和大家分享一下,希望你能学会Linux关闭防火墙命令 。1) 永久性生效,重启后不会复原开启: chkconfig iptables on关闭: chkconfig ... -
Linux系统 防火墙命令
2020-12-15 18:52:45CentOS7防火墙设置Linux系统防火墙设置一、FirewallD简介二、FirewallD特性三、FirewallD配置 一、FirewallD简介 FirewallD 提供了支持网络/防火墙区域(zone)定义网络链接以及接口安全等级的动态防火墙管理工具。它... -
Linux防火墙设置命令的几种方法
2019-02-14 10:56:00iptables防火墙 1、基本操作 # 查看防火墙状态 service iptables status # 停止防火墙 service iptables stop # 启动防火墙 service iptables start # 重启防火墙 service iptables restart # 永久关闭... -
linux 防火墙常用命令
2021-05-11 11:09:29一、iptables防火墙1、基本操作# 查看防火墙状态service iptables status# 停止防火墙service iptables stop# 启动防火墙service iptables start# 重启防火墙service iptables restart# 永久关闭防火墙chkconfig ... -
Linux开启和关闭防火墙命令详述
2021-05-14 01:58:24开启: chkconfig iptables on关闭: chkconfig iptables off2) 即时生效,重启后失效:开启: service iptables start关闭: service iptables stop需要说明的是对于Linux下的其它服务都可以用以上命令执行开启和... -
Linux防火墙-firewalld
2021-01-09 03:34:211、基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld 停止: systemctl disable firewalld 禁用: systemctl stop firewalld 2、Centos7操作 1、启动一个服务 ... -
Linux永久关闭防火墙命令
2022-01-13 00:01:31第一步: systemctl stop firewalld.service (暂时关闭防火墙服务,系统重启后防火墙还会打开) 第二步: systemctl disable firewalld.service(通过关闭防火墙服务,开机自动启动,来做到永久关闭防火墙服务) ... -
【Linux篇】Linux防火墙常用命令合集
2022-03-12 22:29:39查看防火墙状态: firewall-cmd --state 停止/重启/启动 防火墙 systemctl stop firewalld.service systemctl restart firewalld.service systemctl start firewalld.service 禁止/启用 firewall开机启动 ... -
linux的防火墙常用命令
2022-04-26 20:45:33一、下面是red hat/CentOs7关闭防火墙的命令! 1:查看防火状态 systemctl status firewalld service iptables status 2:暂时关闭防火墙 systemctl stop firewalld service iptables stop 3:永久关闭防火墙 systemctl ... -
Linux关闭防火墙命令(永久性关闭)
2020-08-21 15:18:14下面是CentOs7关闭防火墙的命令! 1:查看防火状态 systemctl status firewalld 如果是这样就开着呢 如果是这样就是关着 2:暂时关闭防火墙 systemctl stop firewalld 3:重启防火墙 systemctl enable firewalld 5:... -
Linux 配置防火墙
2021-09-02 19:15:11Linux 配置防火墙 一、图形化的形式 1.开启LAMP systemctl start httpd 2.查看本地IP地址 ip addr 3.本地IP为 192.168.31.150 本地访问 外部浏览器就无法访问 4.此时配置防火墙 firewall-config 此时,出现... -
Linux下常用防火墙命令
2020-11-09 22:44:13CentOS7 的防火墙配置跟以前版本有很大区别,CentOS7这个版本的防火墙默认使用的是firewall, 这里有个参考地址:https://www.cnblogs.com/sucretan2010/p/10835175.html 1、关闭防火墙: 1 ... -
linux查看防火墙是否关闭的实例方法
2021-01-09 04:04:46一、service方式 查看防火墙状态: [root@centos6 ~]# service iptables status iptables:未运行防火墙。 推荐教程:linux教程 ...CentOS7 的防火墙配置跟以前版本有很大区别,CentOS7这个版本的防火墙默认使用的 -
linux查看防火墙命令-两种版本
2020-07-23 23:26:58red hat64 centos7 防火墙命令 1.查看防火状态 systemctl status firewalld service iptablesstatus 2.暂时关闭防火墙 systemctl stop firewalld service iptablesstop 3.永久关闭防火墙 systemctl disable ... -
linux查看防火墙状态及开启关闭命令
2021-05-12 15:45:35存在以下两种方式:一、service方式查看防火墙状态[root@localhost ~]# service iptables statusiptables:未运行防火墙。或者(英文)iptables:Firewall is not running.开启防火墙:[root@localhost ~]# service ... -
工作总结之linux防火墙配置命令适用centos7、centos8
2022-06-06 10:42:52防火墙配置 -
Linux下开启/关闭防火墙命令
2021-05-09 04:46:15iptables用于过滤数据包,属于网络层防火墙.firewall能够允许哪些服务可用,那些端口可用.... 属于更高一层的防火墙。firewall的底层是使用iptables进行数据过滤,建立在iptables之上。1) 永久性生效,重启后不会...