linux配置防火墙 Centos7下 添加 端口白名单

简介: linux配置防火墙 Centos7下 添加 端口白名单

最近在阿里云服务器centos7上部署项目 要开启8484端口 , CentOS 7默认使用的是firewall作为防火墙 在firewall下开启端口白名单

 systemctl stop firewalld 关闭    systemctl disable firewalld  开机不启永久关闭  

1.查看下防火墙的状态:systemctl status firewalld    

需要开启防火墙 systemctl start firewalld.service  

firewall-cmd --zone=public --list-ports       ##查看已开放的端口

2.添加8484端口到白名单 执行

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

提示 success 表示成功

命令含义

--zone #作用域

--add-port=8484/tcp #添加端口,格式为:端口/通讯协议

--permanent #永久生效,没有此参数重启后失效

3.重启防火墙:添加成功之后需要重启防火墙

firewall-cmd --reload

4.测试

其他常用命令:

firewall-cmd --state                          ##查看防火墙状态,是否是running

firewall-cmd --reload                          ##重新载入配置,比如添加规则之后,需要执行此命令

firewall-cmd --get-zones                      ##列出支持的zone

firewall-cmd --get-services                    ##列出支持的服务,在列表中的服务是放行的

firewall-cmd --query-service ftp              ##查看ftp服务是否支持,返回yes或者no

firewall-cmd --add-service=ftp                ##临时开放ftp服务

firewall-cmd --add-service=ftp --permanent    ##永久开放ftp服务
firewall-cmd --remove-service=ftp --permanent  ##永久移除ftp服务
firewall-cmd --add-port=80/tcp --permanent    ##永久添加80端口
firewall-cmd --remove-port=80/tcp --permanent    ##永久添加80端口

firewall-cmd --zone=public --list-ports       ##查看已开放的端口


iptables -L -n                                ##查看规则,这个命令是和iptables的相同的

man firewall-cmd  

有的时候还要设置 SeLinux

sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/configsetenforce 0

vi /etc/security/limits.conf

root soft nofile 65535

root hard nofile 65535

需求:正常情况是服务开启3306端口,但是现在是 只想让某个ip访问3306,也就是3306只给固定的IP开放,然后别的ip就扫码不到

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.11.169" port protocol="tcp" port="3306" accept"

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.11.8" port protocol="tcp" port="3306" accept"

firewall-cmd --list-all                      ##查看全部

firewall-cmd --reload

 

目录
相关文章
|
2天前
|
Ubuntu Linux 编译器
【Linux】详解动静态库的制作和使用&&动静态库在系统中的配置步骤
【Linux】详解动静态库的制作和使用&&动静态库在系统中的配置步骤
|
2天前
|
消息中间件 安全 Linux
服务器(Linux)在线下载activeMQ以及配置打开
服务器(Linux)在线下载activeMQ以及配置打开
12 3
|
2天前
|
安全 Linux Shell
|
2天前
|
网络协议 Linux 网络安全
CentOS 7 防火墙指令
本文介绍了CentOS 7中管理防火墙`firewalld`的指令。
14 0
|
2天前
|
Unix Shell Linux
在 Linux 上把 Vim 配置为默认编辑器
在 Linux 上把 Vim 配置为默认编辑器
|
2天前
|
存储 Web App开发 Ubuntu
整理16款适用于较旧低配置电脑的最佳Linux发行版
在本指南中,趣云笔记(https://www.ecscoupon.com/)介绍了一些最好的Linux发行版,你可以将它们安装在旧PC上并为其注入新的活力。
42 0
|
2天前
|
Linux 数据安全/隐私保护
Linux 读写权限的配置
Linux 读写权限的配置
13 0
|
2天前
|
存储 安全 Linux
linux centos7中使用 Postfix 和Dovecot搭建邮件系统
linux centos7中使用 Postfix 和Dovecot搭建邮件系统
|
2天前
|
Linux 网络安全 数据库
linux centos系统搭建samba文件服务器 NetBIOS解析 (超详细)
linux centos系统搭建samba文件服务器 NetBIOS解析 (超详细)
|
2天前
|
关系型数据库 MySQL Linux
Linux CentOs7 安装Mysql(5.7和8.0版本)密码修改 超详细教程
Linux CentOs7 安装Mysql(5.7和8.0版本)密码修改 超详细教程