Engineer-Exec02-参考解析

案例1:设置SELinux保护
为虚拟机 server0、desktop0 配置SELinux
1)确保 SELinux 处于宽松模式(permissive)
2)在每次重新开机后,此设置必须仍然有效
[root@localhost ~]# vim /etc/selinux/config

This file controls the state of SELinux on the system.

SELINUX= can take one of these three values:

enforcing - SELinux security policy is enforced.

permissive - SELinux prints warnings instead of enforcing.

disabled - No SELinux policy is loaded.

SELINUX=permissive

SELINUXTYPE= can take one of these two values:

targeted - Targeted processes are protected,

minimum - Modification of targeted policy. Only selected processes are protected.

mls - Multi Level Security protection.

SELINUXTYPE=targeted

案例2:虚拟机 server0操作, /dev/vdb 上按以下要求建立分区:

采用默认的 mbr 分区模式
– 第1个分区 /dev/vdb1 的大小为 3G
– 第2个分区 /dev/vdb2 的大小为 1G
– 第3个分区 /dev/vdb3 的大小为 1G
– 第4个分区 /dev/vdb4为扩展分区
– 在划分三个分区逻辑分区/dev/vdb[5-6],
– 分区大小依次为600M、800M
[root@server0 ~]# fdisk /dev/vdb

案例3:Shell脚本(利用位置变量,实现用户输入参数)
为系统 server0 书写脚本/root/user.sh
运行脚本,可以判断用户输入的用户是否存在
如果存在,输出用户基本信息(id 用户名)
如果用户,不存在则创建用户,并输出用户创建成功
[root@server0 ~]# vim /root/user.sh
#!/bin/bash
id $1 &> /dev/null
if [ $? -eq 0 ];then
echo $1用户已存在
id $1
else
useradd $1
echo $1用户创建成功
fi
[root@server0 ~]# chmod +x /root/user.sh

案例4:实现本机server0 的Web服务
1)利用httpd软件搭建Web服务,页面显示内容为 小蝌蚪找妈妈
echo ‘

小蝌蚪找妈妈’ > /var/www/html/index.html

案例5:实现本机server0 的防火墙配置
1)修改虚拟机 server0防火墙配置,明确拒绝所有客户端访问(默认区域修改为block)
[root@server0 ~]# firewall-cmd --set-default-zone=block
2)在虚拟机 desktop0上测试能否访问server0 的Web服务
3)在虚拟机 desktop0上测试能否 ping通 虚拟机 server0

案例6:实现本机server0 的防火墙配置
1)修改虚拟机 server0防火墙配置,将默认区域修改为public
[root@server0 ~]# firewall-cmd --set-default-zone=public
2)在虚拟机 desktop0上测试能否访问server0 的Web服务
3)在虚拟机 desktop0上测试能否 ping通 虚拟机 server0

案例7:实现本机server0 的防火墙配置
1)修改虚拟机 server0防火墙配置,将默认区域修改为public
root@server0 ~]#firewall-cmd --set-default-zone=public
2)修改虚拟机 server0防火墙配置,在public区域中添加http协议,实现永久配置
root@server0 ~]# firewall-cmd --permanent --zone=public --add-service=http
3)在虚拟机 desktop0上测试能否访问server0 的Web服务

案例8:在server上操作,验证端口转发策略
– 从desktop0上访问server0的5423端口,与访问server0的80端口效果一样
[root@server0 ~]# firewall-cmd --permanent --zone=trusted --add-forward-port=port=5423:proto=tcp:toport=80 #添加永久配置
[root@server0 ~]# firewall-cmd --reload #重载服务
[root@server0 ~]# firewall-cmd --list-all #确认运行时规则
trusted (default, active)
interfaces: eth1 eth2 eth0 team0
sources:
services:
ports:
masquerade: no
forward-ports: port=5423:proto=tcp:toport=80:toaddr=
icmp-blocks:
rich rules:
[root@desktop0 ~]# firefox 172.25.0.11:5423 #客户端测试,禁止本机测试
[root@desktop0 ~]# firefox 172.25.0.11:80

发布了55 篇原创文章 · 获赞 0 · 访问量 441

猜你喜欢

转载自blog.csdn.net/weixin_45533230/article/details/103642366