CentOS 7.0如何安装配置iptables和seLinux以及firewalld
一、配置防火墙,开启80端口、3306端口 CentOS .0默认使用的是firewall作为防火墙,这里改为iptables防火墙。 、关闭firewall: systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动 、安装iptables防火墙 yum install iptables-services #安装
显示ok以后,就表示已经安装成功,那么就继续执行下面 vi /etc/sysconfig/iptables #编辑防火墙配置文件
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [:]
:FORWARD ACCEPT [:]
:OUTPUT ACCEPT [:]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
:wq! #保存退出 systemctl restart iptables.service #最后重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动
二、关闭SELINUX vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! #保存退出 setenforce #使配置立即生效,如果永远生效的话,直接reboot重启。省略布尔值介绍。。。。
具体介绍:http://cn.linux.vbird.org/linux_basic/0440processcontrol_5.php#selinux_daemon
三: firewalld的介绍与简单应用 CentOS7的默认防火墙是firewalld,在之前使用iptables时,关闭了firewalld服务,现在反过来关闭iptables服务,打开firewalld服务:
systemctl disable iptables
systemctl stop iptables
systemctl enable firewalld
systemctl start firewalld 打开firewalld服务之后,iptables相关的命令其实也可以继续使用的,但在CentOS7中不用那么操作,因为firewalld有自己的命令。
firewalld有两个基础概念,zone和service,每个zone里面有不同的iptables规则,默认一共有9个zone,CentOS7默认zone为public,查看系统所有zone,使用命令
firewall-cmd --get-zones //查看所有zone
firewall-cmd --get-default-zone //查看默认zone 9个zone的简单介绍: drop(丢弃):任何接受的网络数据包都被丢弃,没有任何回复。仅能有发送出去的网络连接。
block(限制):任何接受的网络连接被IPv4的 icmp-host-prohibited 信息和 IPv6 的icmp6-adm-prohibited 信息所拒绝。
public (公共) :在公共区域内使用,不能相信网络内的其他计算机不会对你的计算机造成危害,只能接收经过选取的连接。
external (外部):特别是为路由器启用了伪装功能的外部网。你不能信任来自网络的其他计算,不能相信它们不会对你的计算机造成危害,只能接收经过选择的连接。
dmz(非军事区):用于的非军事区内的电脑,此区域内可公开访问,可以有限地进入你的内部网络,仅仅接收经过选择的连接。
work(工作):用于工作区。你可以基本相信网络内的其他电脑不会危害你的电脑。仅仅接收经过选择的连接。
home(家庭):用于家庭网络。你可以基本信任网络内的其他计算机不会危害你的计算机。仅仅接收经过选择的连接。
internal(内部):用于内部网络。你可以基本上信任网络内的其他计算机不会威胁你的计算机。仅仅接收经过选择的连接。
trusted(信任):可接受所有的网络连接 几个关于zone的命令
# firewall-cmd --set-default-zone=work //设定默认zone
# firewall-cmd --get-zone-of-interface=ens33 //查看指定网卡
# firewall-cmd --zone=public --add-interface=lo //给指定网卡设置zone
# firewall-cmd --zone=dmz --change-interface=lo //针对网卡更改zone
# firewall-cmd --zone=dmz --remove-interface=lo //针对网卡删除zone
# firewall-cmd --get-zctive-zones //查看系统所有网卡所在的zone fired中的service service 就是zone下面的一个子单元,每个zone里都使用了不同的service,而service就是针对服务(端口)做的iptables规则。
firewall-cmd --get-services //查看当前系统所有service
这些service都是由一个个配置文件定义的,配置文件的模版子啊/usr/lib/firewalld/services/目录下,真正生效的配置文件则在/etc/firewalld/services/目录下(默认为空) 关于service的一些操作命令:
# firewall-cmd --get-services
//查看所有的servies
# firewall-cmd --list-services
//查看当前zone下有哪些service
# firewall-cmd --zone=public --add-service=http
//把http服务增加到public zone下面
# firewall-cmd --zone=public --remove-service=http
//把http服务移除
# ls /usr/lib/firewalld/zones/
//zone的配置文件模板
# firewall-cmd --zone=public --add-service=http --permanent
//更改配置文件,否则只是保存在内存中,之后会在/etc/firewalld/zones目录下面生成配置文件
实例:
需求:ftp服务自定义端口1121,需要在work zone下面放行ftp。
cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services/
vi /etc/firewalld/services/ftp.xml
修改ftp端口号 <?xml version="1.0" encoding="utf-8"?>
<service>
<short>FTP</short>
<description>FTP is a protocol used for remote file transfer. If you plan to make your FTP server publicly available, enable this option. You need the vsftpd package installed for this option to be useful.</description>
<port protocol="tcp" port=""/> ##修改端口为1121
<module name="nf_conntrack_ftp"/>
</service>
[root@zlinux ~]# cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/
[root@zlinux ~]# vi /etc/firewalld/zones/work.xml //增加ftp相关配置 <?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Work</short>
<description>For use in work areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name="ssh"/>
<service name="dhcpv6-client"/>
<service name="ftp"/> ##增加ftp
</zone>
[root@zlinux ~]# firewall-cmd --reload //重新加载
success
[root@zlinux ~]# firewall-cmd --zone=work --list-services //查看是否有ftp
ssh dhcpv6-client ftp
firewalld一些常用的语句
查看默认的zone,结果为trusted
firewall-cmd --get-default-zone
public
设置默认zone为trusted
firewall-cmd --set-default-zone=trusted
success
显示当前正在使用的zone消息
firewall-cmd --get-active-zones
trusted
interfaces: eno16777736
显示系统预定义的zone,默认是9个
firewall-cmd --get-zones
block dmz drop external home internal public trusted work
显示系统预定义的服务名称:
firewall-cmd --get-services
amanda-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns ftp high-availability http https imaps ipp ipp-client ipsec kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxy pmwebapi pmwebapis pop3s postgresql proxy-dhcp radius rpc-bind samba samba-client smtp ssh telnet tftp tftp-client transmission-client vnc-server wbem-https
查询eno16接口和那个zone匹配,网卡与trusted匹配,则该网卡的流量执行eno16中定义的规则,默认允许访问所以的服务:
firewall-cmd --get-zone-of-interface=eno16777736
trusted
显示所以zone及其相对应的规则信息
firewall-cmd --list-all-zone
block
interfaces:
sources:
services:
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules: dmz
interfaces:
sources:
services: ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
.......
在public这个zone中添加允许访问ftp服务的规则
firewall-cmd --add-service=ftp --zone=public
success
从public这个zone中删除允许访问ftp服务的规则
firewall-cmd --remove-service=ftp --zone=public
success
在public这个zone中添加允许访问3306端口的规则
firewall-cmd --add-port=/tcp --zone=public
从public这个zone中删除允许访问3306端口的规则
firewall-cmd --remove-port=/tcp --zone=public
success
将eno16网卡和public绑定,以后从该接口进入的流量,匹配到public中的规则
firewall-cmd --add-interface=eno16 --zone=public
success
将eno16网卡与public解除绑定
firewall-cmd --remove-interface=eno16 --zone
trusted
将源ip地址1.1.1.1与public绑定,以后该主机访问本机时匹配public中的规则
firewall-cmd --add-source=1.1.1.1 --zone=public
success
在public这个zone中添加一条永久规则(允许访问3306端口),规则重启防火墙后依然生效
firewall-cmd --permanent --add-port=/tcp --zone=public
重新加载读取防火墙规则
firewall-cmd --reload
CentOS 7.0如何安装配置iptables和seLinux以及firewalld的更多相关文章
- 在 CentOS 7.0 上安装配置 Ceph 存储
来自: https://linux.cn/article-6624-1.html Ceph 是一个将数据存储在单一分布式计算机集群上的开源软件平台.当你计划构建一个云时,你首先需要决定如何实现你的存储 ...
- Centos 7环境下安装配置Hadoop 3.0 Beta1简记
前言 由于以前已经写过一篇Centos 7环境下安装配置2.8的随笔,因此这篇写得精简些,只挑选一些重要环节记录一下. 安装环境为:两台主机均为Centos 7.*操作系统,两台机器配置分别为: 主机 ...
- CentOS 7.0编译安装Nginx1.6.0+MySQL5.6.19+PHP5.5.14
准备篇: CentOS 7.0系统安装配置图解教程 http://www.osyunwei.com/archives/7829.html 一.配置防火墙,开启80端口.3306端口 CentOS 7. ...
- CentOS 7.0编译安装Nginx1.6.0+MySQL5.6.19+PHP5.5.14方法分享
一.配置防火墙,开启80端口.3306端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop fi ...
- 阿里云服务器 ECS 部署lamp:centos+apache+mysql+php安装配置方法 (centos7)
阿里云服务器 ECS 部署lamp:centos+apache+mysql+php安装配置方法 (centos7) 1.效果图 1 2. 部署步骤 1 1. mysql安装附加(centos7) 7 ...
- CentOS下使用yum安装配置和使用svn
安装说明 系统环境:CentOS-6.3安装方式:yum install (源码安装容易产生版本兼容的问题)安装软件:系统自动下载SVN软件 检查已安装版本 ? 1 2 3 4 5 6 7 8 9 1 ...
- CentOS 7 Xinetd服务安装配置
CentOS 7 Xinetd服务安装配置 目录 CentOS 7 Xinetd服务安装配置 一.Linux守护进程与初始化进程 1. 什么是守护进程 2. 什么是初始化 二.Linux独立启动进程和 ...
- centos 7.0 编译安装php 7.0.3
php下载页面 http://cn2.php.net/downloads.php 7.0.3多地区下载页面 http://cn2.php.net/get/php-7.0.3.tar.gz/from/a ...
- CentOS 6.0下面安装JDK7
下载地址:http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.html 1. 安 ...
随机推荐
- promise从易到难
Chapter 1 // 需求:你要封装一个方法,我给你一个要读取文件的路径,你这个方法能帮我读取文件,并把内容返回给我 const fs = require('fs') const path = r ...
- 双飞翼布局介绍-始于淘宝UED-2011年淘宝玉伯写的
仔细分析各种布局的技术实现,可以发现下面三种技术被经常使用: 浮动 float 负边距 negative margin 相对定位 relative position 这是实现布局的三个最基本的原子技术 ...
- uvm_transaction——事物
文件: src/base/uvm_transaction.svh 类: uvm_transaction uvm_transaction继承自uvm_object,添加了timing和record ...
- 洛谷 P1376 机器工厂
题目描述 小T开办了一家机器工厂,在N(N<=10000)个星期内,原材料成本和劳动力价格不断起伏,第i周生产一台机器需要花费Ci(1<=Ci<=5000)元.若没把机器卖出去,每保 ...
- Win7下vc++6.0打开项目出现问题的解决方案
Win7下vc++6.0打开项目出现Microsoft(R) Developer Studio以及Unable to register this add-in because its DLLRegis ...
- Luogu P5349 幂
大力数学题,发现自己好久没写多项式水平急速下降,求逆都要写挂233 首先看到关于多项式的等比数列求和,我们容易想到先求出每一项的系数然后最后累加起来即可,即设\(f_i=\sum_{n=0}^{\in ...
- 原生JS forEach()和map()遍历,jQuery$.each()和$.map()遍历
一.原生JS forEach()和map()遍历 共同点: 1.都是循环遍历数组中的每一项. 2.forEach() 和 map() 里面每一次执行匿名函数都支持3个参数:数组中的当前项item,当前 ...
- Bootstrap-datepicker设置开始时间结束时间范围
$('.form_datetime').datepicker({ format: 'yyyy-mm-dd', weekStart: 1, startDate: '+1', endD ...
- NoSuchBeanDefinitionException: No qualifying bean of type 'com.bj186.ssm.mapper.EmployeeMapper' available: expected at least 1 bean which qualifies as autowire candidate
在搭建SSM spring springmvc mybatis整合的时候, 遇到了这个问题 说说我的问题吧!我在进行单元测试的时候,出现了这个错误,网上一查才知道是,配置文件中没有写扫描包信息.一看 ...
- How To:Linux下如何通过命令检查网卡是否插上网线
主要工具为ethtool来检查,主要关注的字段为"Link detected",注意如下的输出,其中em4实际物理上并未插上网线,而em1是插上网线的: # ethtool em4 ...