SELinux 概述
? Security-Enhanced Linux
- 美国 NSA 国家安全局主导开发, 一套增强 Linux 系统安
全的强制访问控制体系
- 集成到 Linux 内核 (2.6 及以上) 中运行
- RHEL7 基于 SELinux 体系针对用户, 进程, 目录和文件
提供了预设的保护策略, 以及管理工具
? SELinux 的运行模式
- - enforcing(强制),permissive(宽松)
- - disabled(彻底禁用)
任何状态变成 disabled(彻底禁用), 都必须通过重起 reboot
? 切换运行模式
- 临时切换: setenforce 1|0
- 固定配置:/etc/selinux/config 文件
两台虚拟机均做
- [root@server0 ~]# getenforce
- Enforcing
- [root@server0 ~]# setenforce 0
- [root@server0 ~]# getenforce
- Permissive
- [root@server0 ~]# vim /etc/selinux/config #下一次开机后生效
- SELINUX=permissive
- ###############################################################
用户初始化文件
? 影响指定用户的 bash 解释环境
- ~/.bashrc, 每次开启 bash 终端时生效
? 影响所有用户的 bash 解释环境
- /etc/bashrc, 每次开启 bash 终端时生效
- [root@server0 ~]# vim /root/.bashrc
- alias hello='echo hello'
- [root@server0 ~]# vim /home/student/.bashrc
- alias hi='echo hi'
- [root@server0 ~]# vim /etc/bashrc
- alias haha='echo haha'
root 可以执行:
hello haha
student 可以执行:
- hi haha
- ############################################################
配置聚合连接(网卡绑定, 链路聚合)
作用: 网卡设备的冗余
热备份 (activebackup) 连接冗余
1. 创建虚拟网卡 team0 (参考 man teamd.conf) /example 全文搜索
nmcli connection add type team
con-name team0 ifname team0 autoconnect yes
config '{"runner": {"name":"activebackup"}}'
nmcli connection 添加 类型为 team
配置文件名字 team0 ifconfig 显示的名字为 team0 每次开机自动启用
配置 热备份方式
2. 添加成员
nmcli connection add type team-slave con-name team0-1 ifname eth1 master team0
nmcli connection add type team-slave con-name team0-2 ifname eth2 master team0
nmcli connection 添加 类型为 team 的奴隶设备 配置文件名为 team0-1 奴隶的网卡名为 eth1 加入的组织为 team0
3. 配置 IP 地址
[root@server0 ~]# nmcli connection modify team0 ipv4.method manual ipv4.addresses 192.168.1.1/24 connection.autoconnect yes
4. 激活
nmcli connection up team0
- nmcli connection up team0-1
- nmcli connection up team0-2
5. 验证查看
- teamdctl team0 state
- ifconfig eth1 down
- teamdctl team0 state
如果配置错误, 可以从头来, 删掉从新做
nmcli connection delete team0
- nmcli connection delete team0-1
- nmcli connection delete team0-2
- #############################################################
ipv6 地址配置
ip 地址: 唯一标识网络中主机地址
ipv4 地址:
32 个二进制 分成 4 段 最后用 点 分隔 用 10 进制表示
ipv6 地址:
128 个二进制 分成 8 段 最后用 冒号 分隔 用 16 进制表示
每段内连续的前置 0 可省略, 连续的多个 : 可简化为 ::
虚拟机 server0:
nmcli connection modify 'System eth0' ipv6.method manual
ipv6.addresses 2003:ac18::305/64 connection.autoconnect yes
- nmcli connection up 'System eth0'
- ping6 2003:ac18::305
- ################################################################
搭建基本 web 服务
服务端: 虚拟机 Server0
1. 安装一个可以提供 Web 功能软件
[root@server0 ~]# yum -y install httpd
2. 启动 httpd 服务
- [root@server0 ~]# systemctl restart httpd #重起 httpd 服务
- [root@server0 ~]# systemctl enable httpd #设置 httpd 服务, 开机自启动
3. 书写自己的页面文件
默认存放网页文件的路径:/var/www/html
默认网页文件名字: index.html
- [root@server0 ~]# vim /var/www/html/index.html
- <marquee><font color=red><h1>NSD1801 万岁 阳光明媚
客户端: 虚拟机 Server0
[root@server0 ~]# firefox 172.25.0.11
搭建基本 FTP 服务(文件传输)
服务端: 虚拟机 Server
1. 安装一个可以提供 FTP 功能软件
[root@server0 ~]# yum -y install vsftpd
2. 启动 httpd 服务
- [root@server0 ~]# systemctl restart vsftpd #重起 vsftpd 服务
- [root@server0 ~]# systemctl enable vsftpd #设置 vsftpd 服务, 开机自启动
3. 默认 vsftpd 共享路径: /var/ftp
客户端: 虚拟机 Server
- [root@server0 ~]# firefox ftp://172.25.0.11
- ##############################################################
防火墙策略的应用
隔离作用
允许出站, 过滤入站
硬件防火墙
软件防火墙
RHEL7 的防火墙体系
? 系统服务: firewalld
? 管理工具: firewall-cmd,firewall-config(图形)
预设安全区域
? 根据所在的网络场所区分, 预设保护规则集
- public : 仅允许访问本机的 sshd 等少数几个服务
- trusted : 允许任何访问
- block : 阻塞任何来访请求 (明确回应拒绝)
- drop : 丢弃任何来访的数据包 (没有明确回应, 直接丢弃)
防火墙的判断规则: 匹配及停止
1. 客户端请求中的来源 IP 地址, 查看本身所有区域的规则, 如果有一个区域规则有该 IP 地址的规则, 则进入该区域
2. 进入默认区域 (默认区域一般为 public)
############################################################
默认区域的案例
虚拟机 Server0:
[root@server0 ~]# firewall-cmd --get-default-zone #查看默认区域
虚拟机 desktop0:
[root@desktop0 ~]# ping -c 2 172.25.0.11 #可以通行
虚拟机 Server0:
- [root@server0 ~]# firewall-cmd --set-default-zone=block #修改默认区域
- [root@server0 ~]# firewall-cmd --get-default-zone
虚拟机 desktop0:
[root@desktop0 ~]# ping -c 2 172.25.0.11 #不可以通信, 有回应
虚拟机 Server0:
- [root@server0 ~]# firewall-cmd --set-default-zone=drop
- [root@server0 ~]# firewall-cmd --get-default-zone
虚拟机 desktop0:
- [root@desktop0 ~]# ping -c 2 172.25.0.11 #不可以通信, 没有回应
- ################################################################
常见的协议:
http 超文本传输协议
https 安全的超文本传输协议
ftp 文件传输协议
tftp 简单文件传输协议
telnet 远程管理协议
dns 域名解析协议
smtp 邮件协议
pop3 收邮件协议
snmp 简单的管理协议
服务案例
虚拟机 Server0
- [root@server0 ~]# firewall-cmd --set-default-zone=public
- [root@server0 ~]# firewall-cmd --zone=public --list-all #查看区域策略
虚拟机 Desktop0
- [root@desktop0 ~]# firefox 172.25.0.11 #不可以
- [root@desktop0 ~]# firefox ftp://172.25.0.11 #不可以
虚拟机 Server0
- [root@server0 ~]# firewall-cmd --zone=public --add-service=http #添加协议
- [root@server0 ~]# firewall-cmd --zone=public --list-all
虚拟机 Desktop0
- [root@desktop0 ~]# firefox 172.25.0.11 #可以
- [root@desktop0 ~]# firefox ftp://172.25.0.11 #不可以
虚拟机 Server0
- [root@server0 ~]# firewall-cmd --zone=public --add-service=ftp
- [root@server0 ~]# firewall-cmd --zone=public --list-all
虚拟机 Desktop0
- [root@desktop0 ~]# firefox 172.25.0.11 #可以
- [root@desktop0 ~]# firefox ftp://172.25.0.11 #可以
- ############################################################
防火墙策略永久配置
- 永久(permanent)
虚拟机 Server0
- firewall-cmd --reload #重新加载防火墙所有配置
- firewall-cmd --zone=public --list-all
- firewall-cmd --permanent --zone=public --add-service=http #设置永久
- firewall-cmd --zone=public --list-all
- firewall-cmd --reload #重新加载防火墙所有配置
- firewall-cmd --zone=public --list-all
- #################################################################
防火墙对于客户端源 IP 控制
拒绝 172.25.0.10 访问本机的所有服务, 其他客户端都允许
虚拟机 desktop0
[root@desktop0 ~]# firefox 172.25.0.11 #可以
虚拟机 Server0
- firewall-cmd --zone=block --list-all
- firewall-cmd --permanent --zone=block --add-source=172.25.0.10
- firewall-cmd --reload success
- firewall-cmd --zone=block --list-all
虚拟机 desktop0
- [root@desktop0 ~]# firefox 172.25.0.11 #不可以
- ##########################################################
来源: http://www.bubuko.com/infodetail-2663681.html