centos7 防火墙设置 多网卡 内网访问
admin
2024-02-29 06:48:48
0

0 应用场景

服务器有多个网卡:

  • 公网的ip为210.xx.xx.xx(interface为en1)。
  • 内网的为192.xx.xx.xx(interface为en2)。
  • 允许公网ip的443端口,开放所有内网的访问。

注意:下面加粗的命令为实际需要操作的操作,如:开启服务。其他的命令是补充的细节,不需要操作,如:关闭服务。

准备知识:firewall中支持如下不同的区域区隔与过滤规则,之后不同的配置可以参考下面的内容:

区域

drop: 丢弃所有进入的包,而不给出任何响应
block: 拒绝所有外部发起的连接,允许内部发起的连接
public: 允许指定的进入连接
external: 同上,对伪装的进入连接,一般用于路由转发
dmz: 允许受限制的进入连接
work: 允许受信任的计算机被限制的进入连接,类似 workgroup
home: 同上,类似 homegroup
internal: 同上,范围针对所有互联网用户
trusted: 信任所有连接

过滤规则

source: 根据源地址过滤
interface: 根据网卡过滤
service: 根据服务名过滤
port: 根据端口过滤
icmp-block: icmp 报文过滤,按照 icmp 类型配置
masquerade: ip 地址伪装
forward-port: 端口转发
rule: 自定义规则

1 开启服务

开启服务:

systemctl start firewalld.service

关闭服务:

systemctl stop firewalld.service

开机自启:

systemctl enable firewalld.service

取消开机自启:

systemctl disable firewalld.service

2 将内网的interface添加到信任区域

将内网的网卡添加为信任区域:

firewall-cmd --zone=trusted --add-interface=eno2 --permanent

移除信任区:

firewall-cmd --zone=trusted ---remove-interface=eno2 --permanent

列出所有区:(查看en2是否被添加到trusted )

firewall-cmd --list-all-zones

如果没有显示,更新防火墙:

firewall-cmd --reload 

3 开放公网的interface的443端口

将网卡添加为public区域:

firewall-cmd --zone=public --add-interface=eno1 --permanent

在public区域,添加443端口访问权限:

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

移除端口:

firewall-cmd --zone=public --remove-port=443/tcp --permanent

列出所有端口:(查看是否有443)

firewall-cmd --list-ports

更新防火墙:

firewall-cmd --reload 

4 更多命令-help

Usage: firewall-cmd [OPTIONS...]General Options-h, --help           Prints a short help text and exists-V, --version        Print the version string of firewalld-q, --quiet          Do not print status messagesStatus Options--state              Return and print firewalld state--reload             Reload firewall and keep state information--complete-reload    Reload firewall and lose state information--runtime-to-permanentCreate permanent from runtime configuration--check-config       Check permanent configuration for errorsLog Denied Options--get-log-denied     Print the log denied value--set-log-denied=Set log denied valueAutomatic Helpers Options--get-automatic-helpersPrint the automatic helpers value--set-automatic-helpers=Set automatic helpers valuePermanent Options--permanent          Set an option permanentlyUsable for options marked with [P]Zone Options--get-default-zone   Print default zone for connections and interfaces--set-default-zone=Set default zone--get-active-zones   Print currently active zones--get-zones          Print predefined zones [P]--get-services       Print predefined services [P]--get-icmptypes      Print predefined icmptypes [P]--get-zone-of-interface=Print name of the zone the interface is bound to [P]--get-zone-of-source=[/]||ipset:Print name of the zone the source is bound to [P]--list-all-zones     List everything added for or enabled in all zones [P]--new-zone=    Add a new zone [P only]--new-zone-from-file= [--name=]Add a new zone from file with optional name [P only]--delete-zone= Delete an existing zone [P only]--load-zone-defaults=Load zone default settings [P only] [Z]--zone=        Use this zone to set or query options, else default zoneUsable for options marked with [Z]--get-target         Get the zone target [P only] [Z]--set-target=Set the zone target [P only] [Z]--info-zone=   Print information about a zone--path-zone=   Print file path of a zone [P only]IPSet Options--get-ipset-types    Print the supported ipset types--new-ipset= --type= [--option=[=]]..Add a new ipset [P only]--new-ipset-from-file= [--name=]Add a new ipset from file with optional name [P only]--delete-ipset=Delete an existing ipset [P only]--load-ipset-defaults=Load ipset default settings [P only]--info-ipset= Print information about an ipset--path-ipset= Print file path of an ipset [P only]--get-ipsets         Print predefined ipsets--ipset= --set-description=Set new description to ipset [P only]--ipset= --get-descriptionPrint description for ipset [P only]--ipset= --set-short=Set new short description to ipset [P only]--ipset= --get-shortPrint short description for ipset [P only]--ipset= --add-entry=Add a new entry to an ipset [P]--ipset= --remove-entry=Remove an entry from an ipset [P]--ipset= --query-entry=Return whether ipset has an entry [P]--ipset= --get-entriesList entries of an ipset [P]--ipset= --add-entries-from-file=Add a new entries to an ipset [P]--ipset= --remove-entries-from-file=Remove entries from an ipset [P]IcmpType Options--new-icmptype=Add a new icmptype [P only]--new-icmptype-from-file= [--name=]Add a new icmptype from file with optional name [P only]--delete-icmptype=Delete an existing icmptype [P only]--load-icmptype-defaults=Load icmptype default settings [P only]--info-icmptype=Print information about an icmptype--path-icmptype=Print file path of an icmptype [P only]--icmptype= --set-description=Set new description to icmptype [P only]--icmptype= --get-descriptionPrint description for icmptype [P only]--icmptype= --set-short=Set new short description to icmptype [P only]--icmptype= --get-shortPrint short description for icmptype [P only]--icmptype= --add-destination=Enable destination for ipv in icmptype [P only]--icmptype= --remove-destination=Disable destination for ipv in icmptype [P only]--icmptype= --query-destination=Return whether destination ipv is enabled in icmptype [P only]--icmptype= --get-destinationsList destinations in icmptype [P only]Service Options--new-service=Add a new service [P only]--new-service-from-file= [--name=]Add a new service from file with optional name [P only]--delete-service=Delete an existing service [P only]--load-service-defaults=Load icmptype default settings [P only]--info-service=Print information about a service--path-service=Print file path of a service [P only]--service= --set-description=Set new description to service [P only]--service= --get-descriptionPrint description for service [P only]--service= --set-short=Set new short description to service [P only]--service= --get-shortPrint short description for service [P only]--service= --add-port=[-]/Add a new port to service [P only]--service= --remove-port=[-]/Remove a port from service [P only]--service= --query-port=[-]/Return whether the port has been added for service [P only]--service= --get-portsList ports of service [P only]--service= --add-protocol=Add a new protocol to service [P only]--service= --remove-protocol=Remove a protocol from service [P only]--service= --query-protocol=Return whether the protocol has been added for service [P only]--service= --get-protocolsList protocols of service [P only]--service= --add-source-port=[-]/Add a new source port to service [P only]--service= --remove-source-port=[-]/Remove a source port from service [P only]--service= --query-source-port=[-]/Return whether the source port has been added for service [P only]--service= --get-source-portsList source ports of service [P only]--service= --add-module=Add a new module to service [P only]--service= --remove-module=Remove a module from service [P only]--service= --query-module=Return whether the module has been added for service [P only]--service= --get-modulesList modules of service [P only]--service= --set-destination=:
[/]Set destination for ipv to address in service [P only]--service= --remove-destination=Disable destination for ipv i service [P only]--service= --query-destination=:
[/]Return whether destination ipv is set for service [P only]--service= --get-destinationsList destinations in service [P only]Options to Adapt and Query Zones--list-all List everything added for or enabled in a zone [P] [Z]--list-services List services added for a zone [P] [Z]--timeout= Enable an option for timeval time, where timeval isa number followed by one of letters 's' or 'm' or 'h'Usable for options marked with [T]--set-description=Set new description to zone [P only] [Z]--get-description Print description for zone [P only] [Z]--set-short=Set new short description to zone [P only] [Z]--get-short Print short description for zone [P only] [Z]--add-service=Add a service for a zone [P] [Z] [T]--remove-service=Remove a service from a zone [P] [Z]--query-service=Return whether service has been added for a zone [P] [Z]--list-ports List ports added for a zone [P] [Z]--add-port=[-]/Add the port for a zone [P] [Z] [T]--remove-port=[-]/Remove the port from a zone [P] [Z]--query-port=[-]/Return whether the port has been added for zone [P] [Z]--list-protocols List protocols added for a zone [P] [Z]--add-protocol=Add the protocol for a zone [P] [Z] [T]--remove-protocol=Remove the protocol from a zone [P] [Z]--query-protocol=Return whether the protocol has been added for zone [P] [Z]--list-source-ports List source ports added for a zone [P] [Z]--add-source-port=[-]/Add the source port for a zone [P] [Z] [T]--remove-source-port=[-]/Remove the source port from a zone [P] [Z]--query-source-port=[-]/Return whether the source port has been added for zone [P] [Z]--list-icmp-blocks List Internet ICMP type blocks added for a zone [P] [Z]--add-icmp-block=Add an ICMP block for a zone [P] [Z] [T]--remove-icmp-block=Remove the ICMP block from a zone [P] [Z]--query-icmp-block=Return whether an ICMP block has been added for a zone[P] [Z]--add-icmp-block-inversionEnable inversion of icmp blocks for a zone [P] [Z]--remove-icmp-block-inversionDisable inversion of icmp blocks for a zone [P] [Z]--query-icmp-block-inversionReturn whether inversion of icmp blocks has been enabledfor a zone [P] [Z]--list-forward-ports List IPv4 forward ports added for a zone [P] [Z]--add-forward-port=port=[-]:proto=[:toport=[-]][:toaddr=
[/]]Add the IPv4 forward port for a zone [P] [Z] [T]--remove-forward-port=port=[-]:proto=[:toport=[-]][:toaddr=
[/]]Remove the IPv4 forward port from a zone [P] [Z]--query-forward-port=port=[-]:proto=[:toport=[-]][:toaddr=
[/]]Return whether the IPv4 forward port has been added fora zone [P] [Z]--add-masquerade Enable IPv4 masquerade for a zone [P] [Z] [T]--remove-masquerade Disable IPv4 masquerade for a zone [P] [Z]--query-masquerade Return whether IPv4 masquerading has been enabled for azone [P] [Z]--list-rich-rules List rich language rules added for a zone [P] [Z]--add-rich-rule=Add rich language rule 'rule' for a zone [P] [Z] [T]--remove-rich-rule=Remove rich language rule 'rule' from a zone [P] [Z]--query-rich-rule=Return whether a rich language rule 'rule' has beenadded for a zone [P] [Z]Options to Handle Bindings of Interfaces--list-interfaces List interfaces that are bound to a zone [P] [Z]--add-interface=Bind the to a zone [P] [Z]--change-interface=Change zone the is bound to [Z]--query-interface=Query whether is bound to a zone [P] [Z]--remove-interface=Remove binding of from a zone [P] [Z]Options to Handle Bindings of Sources--list-sources List sources that are bound to a zone [P] [Z]--add-source=[/]||ipset:Bind the source to a zone [P] [Z]--change-source=[/]||ipset:Change zone the source is bound to [Z]--query-source=[/]||ipset:Query whether the source is bound to a zone [P] [Z]--remove-source=[/]||ipset:Remove binding of the source from a zone [P] [Z]Helper Options--new-helper= --module= [--family=]Add a new helper [P only]--new-helper-from-file= [--name=]Add a new helper from file with optional name [P only]--delete-helper=Delete an existing helper [P only]--load-helper-defaults=Load helper default settings [P only]--info-helper= Print information about an helper--path-helper= Print file path of an helper [P only]--get-helpers Print predefined helpers--helper= --set-description=Set new description to helper [P only]--helper= --get-descriptionPrint description for helper [P only]--helper= --set-short=Set new short description to helper [P only]--helper= --get-shortPrint short description for helper [P only]--helper= --add-port=[-]/Add a new port to helper [P only]--helper= --remove-port=[-]/Remove a port from helper [P only]--helper= --query-port=[-]/Return whether the port has been added for helper [P only]--helper= --get-portsList ports of helper [P only]--helper= --set-module=Set module to helper [P only]--helper= --get-moduleGet module from helper [P only]--helper= --set-family={ipv4|ipv6|}Set family for helper [P only]--helper= --get-familyGet module from helper [P only]Direct Options--direct First option for all direct options--get-all-chainsGet all chains [P]--get-chains {ipv4|ipv6|eb} Get all chains added to the table [P]--add-chain {ipv4|ipv6|eb}
Add a new chain to the table [P]--remove-chain {ipv4|ipv6|eb}
Remove the chain from the table [P]--query-chain {ipv4|ipv6|eb}
Return whether the chain has been added to the table [P]--get-all-rulesGet all rules [P]--get-rules {ipv4|ipv6|eb}
Get all rules added to chain in table [P]--add-rule {ipv4|ipv6|eb}
...Add rule to chain in table [P]--remove-rule {ipv4|ipv6|eb}
...Remove rule with priority from chain in table [P]--remove-rules {ipv4|ipv6|eb}
Remove rules from chain in table [P]--query-rule {ipv4|ipv6|eb}
...Return whether a rule with priority has been added tochain in table [P]--passthrough {ipv4|ipv6|eb} ...Pass a command through (untracked by firewalld)--get-all-passthroughsGet all tracked passthrough rules [P]--get-passthroughs {ipv4|ipv6|eb} ...Get tracked passthrough rules [P]--add-passthrough {ipv4|ipv6|eb} ...Add a new tracked passthrough rule [P]--remove-passthrough {ipv4|ipv6|eb} ...Remove a tracked passthrough rule [P]--query-passthrough {ipv4|ipv6|eb} ...Return whether the tracked passthrough rule has beenadded [P]Lockdown Options--lockdown-on Enable lockdown.--lockdown-off Disable lockdown.--query-lockdown Query whether lockdown is enabledLockdown Whitelist Options--list-lockdown-whitelist-commandsList all command lines that are on the whitelist [P]--add-lockdown-whitelist-command=Add the command to the whitelist [P]--remove-lockdown-whitelist-command=Remove the command from the whitelist [P]--query-lockdown-whitelist-command=Query whether the command is on the whitelist [P]--list-lockdown-whitelist-contextsList all contexts that are on the whitelist [P]--add-lockdown-whitelist-context=Add the context context to the whitelist [P]--remove-lockdown-whitelist-context=Remove the context from the whitelist [P]--query-lockdown-whitelist-context=Query whether the context is on the whitelist [P]--list-lockdown-whitelist-uidsList all user ids that are on the whitelist [P]--add-lockdown-whitelist-uid=Add the user id uid to the whitelist [P]--remove-lockdown-whitelist-uid=Remove the user id uid from the whitelist [P]--query-lockdown-whitelist-uid=Query whether the user id uid is on the whitelist [P]--list-lockdown-whitelist-usersList all user names that are on the whitelist [P]--add-lockdown-whitelist-user=Add the user name user to the whitelist [P]--remove-lockdown-whitelist-user=Remove the user name user from the whitelist [P]--query-lockdown-whitelist-user=Query whether the user name user is on the whitelist [P]Panic Options--panic-on Enable panic mode--panic-off Disable panic mode--query-panic Query whether panic mode is enabled

参考:https://www.cnblogs.com/happenlee/p/8928843.html

相关内容

热门资讯

linux入门---制作进度条 了解缓冲区 我们首先来看看下面的操作: 我们首先创建了一个文件并在这个文件里面添加了...
C++ 机房预约系统(六):学... 8、 学生模块 8.1 学生子菜单、登录和注销 实现步骤: 在Student.cpp的...
A.机器学习入门算法(三):基... 机器学习算法(三):K近邻(k-nearest neigh...
数字温湿度传感器DHT11模块... 模块实例https://blog.csdn.net/qq_38393591/article/deta...
有限元三角形单元的等效节点力 文章目录前言一、重新复习一下有限元三角形单元的理论1、三角形单元的形函数(Nÿ...
Redis 所有支持的数据结构... Redis 是一种开源的基于键值对存储的 NoSQL 数据库,支持多种数据结构。以下是...
win下pytorch安装—c... 安装目录一、cuda安装1.1、cuda版本选择1.2、下载安装二、cudnn安装三、pytorch...
MySQL基础-多表查询 文章目录MySQL基础-多表查询一、案例及引入1、基础概念2、笛卡尔积的理解二、多表查询的分类1、等...
keil调试专题篇 调试的前提是需要连接调试器比如STLINK。 然后点击菜单或者快捷图标均可进入调试模式。 如果前面...
MATLAB | 全网最详细网... 一篇超超超长,超超超全面网络图绘制教程,本篇基本能讲清楚所有绘制要点&#...
IHome主页 - 让你的浏览... 随着互联网的发展,人们越来越离不开浏览器了。每天上班、学习、娱乐,浏览器...
TCP 协议 一、TCP 协议概念 TCP即传输控制协议(Transmission Control ...
营业执照的经营范围有哪些 营业执照的经营范围有哪些 经营范围是指企业可以从事的生产经营与服务项目,是进行公司注册...
C++ 可变体(variant... 一、可变体(variant) 基础用法 Union的问题: 无法知道当前使用的类型是什...
血压计语音芯片,电子医疗设备声... 语音电子血压计是带有语音提示功能的电子血压计,测量前至测量结果全程语音播报࿰...
MySQL OCP888题解0... 文章目录1、原题1.1、英文原题1.2、答案2、题目解析2.1、题干解析2.2、选项解析3、知识点3...
【2023-Pytorch-检... (肆十二想说的一些话)Yolo这个系列我们已经更新了大概一年的时间,现在基本的流程也走走通了,包含数...
实战项目:保险行业用户分类 这里写目录标题1、项目介绍1.1 行业背景1.2 数据介绍2、代码实现导入数据探索数据处理列标签名异...
记录--我在前端干工地(thr... 这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 前段时间接触了Th...
43 openEuler搭建A... 文章目录43 openEuler搭建Apache服务器-配置文件说明和管理模块43.1 配置文件说明...