Unit iptables.service failed to load - RHEL 7/ CentOS 7/Fedora 中的防火墙

本文介绍在CentOS7中如何禁用firewalld并重新启用iptables服务,包括配置步骤和命令,还提供了开放端口的方法。

第一次使用 CentOS 7,配置防火墙的时候, iptables 服务不能用了,有的时候命令能成功,有的时候又不行,特别是那些写入的操作和服务相关的。在执行 service iptables start/stopservice iptables save 之类的服务命令时会出现 Failed to restart iptables.service: Unit iptables.service failed to load: No such file or directory. 的错误日志。原因是 CentOS 7 升级防火墙为 一个叫 firewalld 的库了。

下面就说一下如何在 Cent7 中像以前一样使用 iptables :

  • 首先关闭并卸载 firewalld
systemctl stop firewalld
systemctl mask firewalld
  • 安装iptables-services

yum install iptables-services

  • 设置开机启动:

systemctl enable iptables

  • 启动服务
systemctl stop iptables  
systemctl start iptables  
systemctl restart iptables  
systemctl reload iptables 
  • 保存设置:

service iptables save

开放某个端口 在/etc/sysconfig/iptables里添加 -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

至于新的 fairwalld 的用法最主要有两条:

  • 开放端口

firewall-cmd --permanent --add-port=80/tcp

  • 查询端口是否开放

firewall-cmd --permanent --query-port=80/tcp

Selinux 原理介绍 自主访问控制 传统 Linux discretionary access control, DAC) 强制访问控制 MAC SELinux 的策略类型:Targeted 默认策略 8. Selinux 的使用 ID SEC OPERATION SELinux 1 filesystem chmod, chown, setfacl, chattr guestfish (selinux-relabel) virt-custmize (--selinux-relabel) touch /.autorelabel 2 service vim /etc/ssh/sshd_config setsebool getsebool 3 firewall iptables, firewalld semanage port ... 4 Selinux vim /etc/selinux/config 1. 上下文关系 guestfish ><fs> selinux-relabel /etc/selinux/targeted/contexts/files/file_contexts / virt-custmize virt-customize \ --selinux-relabel \ ... 8.6.3. 重置 root 密码 # touch /.autorelabel # sync apache yum -y install httpd rpm -qc httpd vim /etc/httpd/conf/httpd.conf echo Hello world > /var/www/html/index.html ls -lZ /var/www/html/index.html ls -ldZ /var/www/html ls -ldZ /var/www ls -ldZ /var systemctl enable --now httpd curl localhost firewall-cmd --permanent --add-service=http firewall-cmd --reload mkdir /srv/www grep /var/www/html /etc/httpd/conf/httpd.conf sed -i 's+/var/www/html+/srv/www+' /etc/httpd/conf/httpd.conf grep /srv/www /etc/httpd/conf/httpd.conf echo Hello huhehaote > /srv/www/index.html systemctl restart httpd curl localhost setenforce 0 curl localhost setenforce 1 curl localhost A # yum search selinux # yum -y install selinux-policy-doc.noarch # mandb # man -k selinux # man httpd_selinux B # yum provides *sealert # yum -y install setroubleshoot-server # sealert -a /var/log/audit/audit.log # semanage fcontext -a -t FILE_TYPE '/srv/www/index.html' # restorecon -v '/srv/www/index.html' C # man semanage fcontext | grep \# # semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?" # restorecon -R -v /web HTTPD_DIR=/srv/www semanage fcontext -a -t httpd_sys_content_t "/${HTTPD_DIR}(/.*)?" restorecon -R -v ${HTTPD_DIR} ls -ldZ /srv/www/{.,*} curl localhost
最新发布
09-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值