CentOS firewall和selinux相关

firewall

CentOS 6.x:

root下

service iptables stop              停止
service iptables start              启动
service iptables status            状态
chkconfig iptables off            禁用
CentOS 7.x:
root下
systemctl stop firewalld.service       停止
systemctl start firewalld.service       启动
systemctl status firewalld.service     状态
systemctl disable firewalld.service   禁用

SElinux

查看selinux的状态:

getenforce   或者     sestatus -v


设置selinux的状态:

1、setenforce 命令设置临时关闭          

setenforce 0 可以临时关闭,但重启之后还是会变成原来的状态

2、vi /etc/sysconfig/selinux      SELINUX=disabled  然后重启                      

修改/etc/sysconfig/selinux文件可以永久地禁用它

### CentOS7 防火墙配置 在 CentOS 7 中,默认使用的防火墙管理工具是 `firewalld`,它提供动态管理防火墙的功能,并支持网络区域的概念。 要查看当前活动的区域服务: ```bash sudo firewall-cmd --get-active-zones ``` 为了永久启用 HTTP HTTPS 流量通过防火墙,可以运行如下命令[^1]: ```bash sudo firewall-cmd --zone=public --add-service=https --permanent ``` 保存更改并重新加载防火墙设置以使这些变化生效: ```bash sudo firewall-cmd --reload ``` 对于更复杂的规则定义,比如允许特定 IP 地址访问 SSH 端口,则可使用以下指令[^2]: ```bash sudo firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="192.0.2.0/24" service name="ssh" accept' --permanent ``` 再次重载 firewalld 来应用新添加的富规则. ### SELinux 配置 SELinux 是一种强制访问控制机制,在默认情况下处于 enforcing 模式下工作。可以通过编辑 `/etc/selinux/config` 文件来调整其行为模式。 当遇到因 SELinux 导致的应用程序权限问题时,通常会先尝试将其临时设为 permissive 模式来进行调试: ```bash setenforce 0 ``` 这不会改变系统的安全策略设定;相反,它只是暂时阻止 SELinux 实施任何拒绝决策。如果希望永久修改此状态,则需编辑上述提到的配置文件中的 `SELINUX=enforcing` 行改为 `permissive` 或者 `disabled`. 有时也需要为某些服务创建自定义的安全上下文标签。例如给定目录赋予 web 内容类型的标签以便 Apache 能够读取其中的数据: ```bash chcon -Rt httpd_sys_content_t /path/to/web/content/ ``` 另外还可以利用 `audit2allow` 工具来自动生成适合环境需求的新模块或修复现有政策缺陷[^3].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值