Linux防火墙-netfilter
- selinux临时关闭 setenforce 0
- selinux永久关闭 vi /etc/selinux/config
- centos7之前使用netfilter防火墙
- centos7开始使用firewalld防火墙
- 关闭firewalld开启netfilter方法
- systemctl stop firewalld
- systemctl disable firewalled
- yum install -y iptables-services
- systemctl enable iptables
- systemctl start iptables
selinux防火墙
- setenforce 0 临时关闭 selinux
- vi /etc/selinux/config 永久关闭 selinux
- selinux一般都是关闭的,因为开启selinux会增大运维管理成本,因为很多服务受限于selinux
- 在关闭selinux后,也不会存在太大的安全问题
[root@hanfeng-001 ~]# vi /etc/selinux/config
将SELINUX=enforcing更改为SELINUX=disabled
然后在重启系统,就会永久关闭selinux
(若是将SELINUXTYPE=targeted 这里更改了,就会无法开启系统!!!千万注意)
Enforcing和Permissive区别
[root@hanfeng-001 ~]# getenforce
Enforcing
[root@hanfeng-001 ~]# setenforce 0 //临时关闭
[root@hanfeng-001 ~]# getenforce
Permissive
[root@hanfeng-001 ~]#
- 区别:
- Permissive是selinux开启了,但是仅仅是遇到这种需要发生阻断的时候,他不需要真正的去阻断,仅仅是一个提醒
netfilter防火墙
-
netfilter防火墙是centos7之前的叫法
-
在centos7的时候,叫做firewalld
-
这 netfilter 和firewalld 两个防火墙机制不太一样,但内部的工具(iptables)用法是一样的
- 可以通过iptables工具,去添加一些规则(比如,开放80端口,开放22端口,关闭8080端口)
-
在centos7中,默认使用的是firewalld,而netfilter防火墙是没有开启的
- 在centos7中,关闭firewalld,去使用netfilte防火墙也是没有问题的
- 关闭firewalld,开启netfilter
- 先systemctl disabled firewalld 停掉firewalld,就是限制开机启动
- 然后systemctl stop firewalld 关闭firewalld服务
- 开启netfilter之前安装 iptables-services 包
- 在安装完成后,就会产生一个iptables服务
- 再systemctl enable iptables 设置开启激动——>(一定要关闭selinux,否则这里操作不了)
- 再systemctl stat iptables 开启iptables服务
关闭firewalld
[root@hf-01 ~]# systemctl disable firewalld //停掉firewalld,就是限制开机启动
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@hf-01 ~]# systemctl stop firewalld //关闭firewalld服务
开启netfilter
在开启之前,需要先安装一个iptables-services包
[root@hf-01 ~]# yum install -y iptables-services
[root@hf-01 ~]# systemctl enable iptables //设置开启激动
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
[root@hf-01 ~]# systemctl start iptables //开启iptables服务
[root@hf-01 ~]#
- 在iptables服务启动之后,用 iptables -nvL 命令查自带的规则
- iptables -nvL 查看默认规则
[root@hf-01 ~]# iptables -nvL //查看默认规则
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
35 2436 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT 22 packets, 3152 bytes)
pkts bytes target prot opt in out source destination
[root@hf-01 ~]#
- iptables 仅仅是netfilter防火墙的一个工具