美文网首页
CENTOS7网络防火墙、网卡、服务配置

CENTOS7网络防火墙、网卡、服务配置

作者: LittleTrue | 来源:发表于2018-09-12 15:13 被阅读0次

防火墙配置:

要想要外网能够访问服务器上的项目,必须满足以下条件:
1、防火墙没有屏蔽端口 (阿里云服务器默认不开启firewall, 阿里云实现了自己的安全管理策略)

2、防火墙有注册允许httpd/ftp服务运行(阿里云服务器默认注册)

3、上层ISP没有屏蔽端口(如果是阿里云则可以直接控制台通过控制安全组来控制,不用通过ISP的限制)

4、已备案域名指向ip(大多数情况下,如果只有一个公网ip访问,80端口是被上层强制关闭的)

防火墙命令: 参考

基础:

systemctl restart firewalld.service 重启
firewall-cmd --state 状态
firewall-cmd --reload 重启
systemctl start firewalld 开启
systemctl stop firewalld 关闭

查看当前开了哪些服务其实一个服务对应一个端口,每个服务对应/usr/lib/firewalld/services下面一个xml文件。
firewall-cmd --list-services

可以通过下面的命令永久添加一个web服务到firewall。
firewall-cmd --permanent --add-service=http//http换成想要开放的service

查看已经开放的端口。默认public可加 --zone=dmz 指定安全域
firewall-cmd --list-ports

永久添加/关闭一个端口到public域 , 重启生效
firewall-cmd --zone=public --add-port=81/tcp --permanent
firewall-cmd --zone=public --remove-port=81/tcp --permanent

网卡和防火墙安全域的关系

如果开启了端口, 服务商ISP也开放了端口, 但是外网还是访问不了,就要开始考虑网卡和安全组的关系。
以4个网卡的服务器为例(使用ipadd r 查看得对应四个网卡名称分别为 em1 -em4), 外网通路的以太网连接线连接到了em3:

查看默认安全域
firewall-cmd --get-default-zone

查看已被激活的 Zone 安全域: firewall-cmd --get-active-zones

查看指定网卡接口em3的安全域信息 firewall-cmd --get-zone-of-interface=em3

查看指定安全域对应接口信息 firewall-cmd --zone=public --list-interfaces

为指定的网卡接口em3分配安全域, (如果不分配, 那么该安全域的端口不会对由该网卡进入的网络生效)
firewall-cmd --zone=public --add-interface=em3 --permanent

如果网卡和安全组对应都正确了,端口还是未开放,那就要开始考虑liunx的某些版本, 如果你的端口没有任何进程在监听, 是永远对外显示关闭状态的,这也是centos较新的版本加的安全新特性。


配置服务:

systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。

启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service

重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service

在开机时启用服务:systemctl enable firewalld.service
在开机时禁用服务:systemctl disable firewalld.service

查看已启动的服务列表:systemctl list-unit-files|grep enabled

查看可以启动的服务列表: firewall-cmd --get-services


centos7上进行网卡/网络配置:

[参考我的另一篇文章](https://www.jianshu.com/writer#/notebooks/28119700/notes/32147099

相关文章

网友评论

      本文标题:CENTOS7网络防火墙、网卡、服务配置

      本文链接:https://www.haomeiwen.com/subject/xspvgftx.html