1. 系统的IP地址由DHCP提供,您可以视其正常,或者您可以按以下信息重新设置为静态IP:
server0.example.com: 172.25.0.11
desktop0.example.com: 172.25.0.10
子网掩码为 255.255.255.0
当前域为 example.com 域 ip 地址范围是 172.25.0.0/255.255.255.0 您将会注意到一些要求明确不允许服务被域 cracker.org 访问。cracker.org 域中的系统在 192.168.0.0/255.255.255.0 子网中
======================================================================================================================================================
2. SELinux 必须在两个系统 desktop0 和 server0 中运行于 Enforcing 模式
vim /etc/sysconfig/selinux
SELINUX=enforcing
setenforce 1
======================================================================================================================================================
3. 按以下要求配置SSH访问:
用户能够从域 example.com 内的客户端通过SSH远程访问您的两个虚拟机系统, 域 cracker.org 内的客户端不能访问您的两个虚拟机系统
firewall-cmd --permanent --zone=block --add-source=192.168.0.0/24
firewall-cmd --reload
======================================================================================================================================================
4. 在系统 desktop0 和 server0 上创建自定义命令名为 psnew 此自定义命令将执行以下命令: /bin/ps aux 此命令对系统中所有用户有效。
vim /etc/bashrc
alias psnew='/bin/ps aux'
source /etc/bashrc 测试命令是否可用
==========================================================================================================================================================
5. 在系统 server0 上配置端口转发。
在 172.25.0.0/24 网络中的系统,访问 server0 的本地端口 5423 将被转发到 80,此设置必须永久有效。
firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=172.25.0.0/24 forward-port port=5423 protocol=tcp to-port=80"
firewall-cmd --reload
可以在 server0 上安装 httpd,并且启动后使用浏览器访问 5423 端口,如果可以看到 httpd welcome 页面,则配置正确,请在 desktop 打开浏览器访问
因为 如果在 server0 上访问,localhost 不会通过 firewalld 规则
=======================================================================================================================================================
6. 在 server0 上按以下要求配置一个链路:
此链路使用接口 eno1 和 eno2
此链路在一个接口失效时仍然能工作
此链路在 server0 使用下面的地址 10.16.0.150/255.255.255.0
此链路在系统重启之后依然保持正常状态
需要在 server0 上执行 “lab teambridge setup” 设置本题目环境
nmcli connection add type team con-name team0 ifname team0 config '{"runner": {"name": "activebackup"}}' #//("config后面的内容man teamd.conf 搜索 EXAMPLES")
nmcli connection modify team0 ipv4.addresses '10.16.0.150/24'
nmcli connection modify team0 ipv4.method manual
nmcli connection add type team-slave con-name team0-port1 ifname eno1 master team0
nmcli connection add type team-slave con-name team0-port2 ifname eno2 master team0
========================================================================================================================================================
7. 在您的 server0 上配置 eth0 使用下列IPv6地址:2001:ac18::16e/64 #改为书后实验
nmcli connection modify eth0 ipv6.addresses 2001:ac18::16e/64 ipv6.method manual
nmcli connection down eth0;nmcli connection up eth0 这样可以重载 eth0 配置,免重启生效
=======================================================================================================================================================
8. 在系统 server0 上配置邮件服务,满足以下要求:
这些系统不接收外部发送来的邮件
在这些系统上本地发送的任何邮件都会自动路由到 smtp0.example.com
从这些系统上发送的邮件显示来自于 example.com
您可以通过发送邮件到本地用户 'student' 来测试您的配置
需要在 server0 和 desktop0 上分别执行 lab smtp-nullclient setup
postconf -e "inet_interfaces = loopback-only"
postconf -e "inet_protocols = all"
postconf -e "mydestination = "
postconf -e "relayhost = [smtp0.example.com]"
postconf -e "myorigin = example.com"
postconf -e "local_transport = error: local delivery disabled"
postconf -e "mynetworks = 127.0.0.0/8 [::1]/128"
systemctl restart postfix
使用 root 登录 server0 ,安装 mutt 软件,并且对 student@desktop0.example.com 发邮件
切换到 student 账户使用 mutt -f imaps://imap0.example.com 进行检查,用户名和密码是 student, 如果可以看到内容说明配置成
配置完毕后,检查,如果没有问题,在 foundation上执行 rht-vmctl reset all 恢复一次虚拟机,避免干扰后面的实验
=======================================================================================================================================================
9. 在 server0 上配置 SMB 服务
您的 SMB 服务器必须是 STAFF 工作组的一个成员
共享 /project 目录共享名必须为 common
只有 example.com 域内的客户端可以访问 common 共享
common 必须是可以浏览的
用户 student 必须能够读取共享中的内容,如果需要的话,验证的密码是redhat
yum install samba samba-client -y;
systemctl enable smb
mkdir /project
firewall-cmd --permanent --add-service=samba
firewall-cmd --reload
vim /etc/samba/smb.conf
workgroup = MYGROUP -> workgroup = STAFF
[common]
path = /project
browseable = yes
hosts allow = 172.25.0.
hosts deny = 192.168.0.
systemctl start smb
smbpasswd -a student
semanage fcontext -a -t samba_share_t '/project(/.*)?'
restorecon -vRF /project
systemctl restart smb
验证 smbclient -U student -L //172.25.0.11/common
================================================================================================================
10. 在server0 共享通过SMB目录 /shared 满足以下要求
共享名为 shared
共享目录 shared 只能被example.com 域中的客户端使用
共享目录 shared 必须可以被浏览
用户 mario 必须能以读的方式访问此共享, 访问密码是 redhat
用户 sasuke 必须能以读写的方式访问此共享, 访问密码是 redhat
此共享永久挂载在 desktop0.example.com 上的 /mnt/multi 目录, 并使用用户 mario 作为认证, 用户 sasuke 应该有写的权限
server0
chown sasuke /shared
vim /etc/samba/smb.conf
[shared]
path = /shared
browseable = yes
write list = sasuke
semanage fcontext -a -t samba_share_t '/shared(/.*)?'
restorecon -vRF /shared
如果用户不存在自己创建(useradd mario;useradd sasuke)
smbpasswd -a mario
smbpasswd -a sasuke
systemctl restart smb
desktop0
yum install -y samba-client cifs-utils
mkdir /mnt/multi
vim /root/smb.txt
username=mario
password=redhat
vim /etc/fstab
//server0.example.com/shared /mnt/multi cifs multiuser,sec=ntlmssp,credentials=/root/smb.txt 0 0
mount -a
cifscreds add server0
测试,如果没有问题,在 foundation上执行 rht-vmctl reset all 恢复一次虚拟机,避免干扰后面的实验
=====================================================================================================================================================
11. 在 server0 配置 NFS 服务,要求如下:
以只读的方式共享目录 /public 同时只能被 example.com 域中的系统访问
以读写的方式共享目录 /protected 能被 example.com 域中的系统访问
访问 /protected 需要通过 Kerberos 安全加密, 您可以使用下面 URL 提供的密钥 http://classroom.example.com/pub/keytabs/server0.keytab
目录 /protected 应该包含名为 confidential 拥有人为ldapuser0 的子目录
用户 ldapuser0 能以读写方式访问 /protected/confidential
配置实验环境 server0 上执行 lab nfskrb5 setup
mkdir /public
mkdir /protected
mkdir /protected/confidential
chown ldapuser0 /protected/confidential
wget http://classroom.example.com/pub/keytabs/server0.keytab
mv server0.keytab /etc/krb5.keytab
restorecon -vRF /etc/krb5.keytab
vim /etc/exports
/public 172.25.0.0/24(ro,sync,no_root_squash)
/protected 172.25.0.0/24(rw,sync,no_root_squash,sec=krb5p)
systemctl enable nfs-server
systemctl restart nfs-server
systemctl enable nfs-secure-server
systemctl restart nfs-secure-server
firewall-cmd --permanent --add-service=nfs
firewall-cmd --reload
====================================================================================================
12. 在 desktop0 上挂载一个来自 server0.example.com 的NFS共享, 并符合下列要求:
/public 挂载在下面的目录上 /mnt/nfsmount
/protected 挂载在下面的目录上 /mnt/nfssecure 并使用安全的方式,密钥下载URL如下: http://classroom.example.com/pub/keytabs/desktop0.keytab
用户 ldapuser0 能够在 /mnt/nfssecure/confidential 上创建文件
这些文件系统在系统启动时自动挂载
在 desktop0 上执行 lab nfskrb5 setup 配置实验环境
mkdir /mnt/nfsmount
mkdir /mnt/nfssecure
wget http://classroom.example.com/pub/keytabs/desktop0.keytab
mv desktop0.keytab /etc/krb5.keytab
restorecon -vRF /etc/krb5.keytab
systemctl restart nfs-secure
systemctl enable nfs-secure
systemctl restart nfs
vim /etc/fstab
server0.example.com:/public /mnt/nfsmount nfs defaults,vers=4,sec=sys 0 0
server0.example.com:/protected /mnt/nfssecure nfs defaults,vers=4,sec=krb5p 0 0
mount -a, 看是否挂载成功,重启客户端再看是否挂载成功 ssh ldapuser0@desktop 密码是 kerberos,测试 /mnt/nfssecure 的写入权限
如果无异常,重启一次检查看是否挂载成功,如果没有问题,在 foundation上执行 rht-vmctl reset all 恢复一次虚拟机,避免干扰后面的实验
============================================================================================
13. 在 server0 上配置一个站点 http://server0.example.com 然后执行下述步骤:
创建一个index.html 拷贝到您的 web 服务器的 DocumentRoot 目录下
来自于 example.com 域的客户端可以访问此Web服务
来自于 cracker.org 域的客户端拒绝访问此Web服务
yum install httpd httpd-manual -y
systemctl enable httpd;systemctl restart httpd
firewall-cmd --permanent --zone=block --add-source=192.168.0.0/24
firewall-cmd --permanent --add-service=http;firewall-cmd --reload
echo "first index" > /var/www/html/index.html
restorecon -vRF /var/www
打开浏览器输入 server0.example.com/manual 打开手册,找到virt host -> Name-based 复制配置
vim /etc/httpd/conf.d/base.conf
ServerName server0.example.com
DocumentRoot /var/www/html
配置虚拟主机
在 Server0 上扩展您的 web 服务器,为站点 http://www0.example.com 创建一个虚拟主机, 然后执行下述步骤:
设置 DocumentRoot 为 /var/www/virtual
创建文件index.html,文件内容为 "www-second",并将文件 index.html 放到虚拟主机的 DocumentRoot 目录下
确保 student 用户能够在 /var/www/virtual 目录下创建文件
注意:原始站点 http://server0.example.com 必须仍然能够正常访问,
默认环境中的 DNS 服务器能够对主机名 www0.example.com 正常解析
mkdir -p /var/www/virtual
echo "second index" > /var/www/virtual/index.html
resotrecon -vRF /var/www
setfacl -m u:student:rwx /var/www/virtual
vim /etc/httpd/conf.d/virtual.conf
ServerName www0.example.com
DocumentRoot /var/www/virtual
systemctl restart httpd
配置安全 web 服务
为站点 http://www0.example.com 配置 TLS加密
一个已签名证书从 http://classroom.example.com/pub/tls/certs/www0.crt 获取
此证书的密钥从 http://classroom.example.com/pub/tls/private/www0.key 获取
此证书的签名授权信息从 http://classroom.example.com/pub/example-ca.crt 获取
firewall-cmd --permanent --add-service=https;firewall-cmd --reload
wget http://classroom.example.com/pub/tls/certs/www0.crt
wget http://classroom.example.com/pub/tls/private/www0.key
wget http://classroom.example.com/pub/example-ca.crt
mv www0.crt /etc/pki/tls/certs/
mv www0.key /etc/pki/tls/private/
mv example-ca.crt /etc/pki/tls/certs/
restorecon -vRF /etc/pki/tls
yum install mod_ssl -y
systemctl restart httpd
访问 http://server0.example.com/manual 手册页面搜索 'SSL/TLS Encryption' 找到 “How to"
vim /etc/httpd/conf.d/https.conf
ServerName www0.example.com
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/www0.crt
SSLCertificateKeyFile /etc/pki/tls/private/www0.key
cat /etc/http/conf.d/ssl.conf |grep Chain 复制最后一行,写入下面配置文件
SSLCertificateChainFile /etc/pki/tls/.......
ServerName www0.example.com
DocumentRoot /var/www/virtual/
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/www0.crt
SSLCertificateKeyFile /etc/pki/tls/private/www0.key
SSLCertificateChainFile /etc/pki/tls/certs/example-ca.crt
systemctl restart httpd
打开浏览器访问 https://www0.example.com 看是否需要浏览器添加证书
配置 web 内容的访问
在您的 server0 上的 web 服务器的 DocumentRoot 目录下,创建一个名为 confidential 的目录,要求如下:
创建包含内容为 "password:redhat" 内容的 index.html 文件到这个目录,
从 server0 上的任何人都可以通过浏览器查看 confidential 目录中的内容,
但是从其它系统不能访问这个目录的内容
mkdir -p /var/www/html/confidential
touch /var/www/html/confidential/index.html
restorecon -vRF /var/www/html/confidential/index.html
打开手册 http://server0.example.com/manual/ -> 找到 access control ->复制 Require ip ip.address
vim /etc/httpd/conf.d/secure.conf
Require ip 127.0.0.1
Require ip 172.25.X.11
systemctl restart httpd
可以使用 elinks 分别在 server0 和 desktop0 上进行测试,http://server0.example.com/confidential/,server0 可以看到内容,desktop0 看不到内容
实现动态 Web 内容
在 server0 上配置提供动态 Web 内容,要求如下:
动态内容由名为 webapp0.example.com 的虚拟主机提供
虚拟主机侦听在端口 8989
客户端访问 http://webapp0.example.com:8989/ 时应该接收到动态生成的 web 页面
在 server0 上执行 lab webapp setup 后,可以在 /home/student/webapp.wsgi 找到 wsgi 脚本文件
此网站必须能被 example.com 域内的所有系统访问
firewall-cmd --permanent --add-port=8989/tcp;firewall-cmd --reload
semanage port -a -t http_port_t -p tcp 8989
yum install -y mod_wsgi
systemctl restart httpd
cp /home/student/webapp.wsgi /var/www/
restorecon -vRF /var/www
cat /usr/share/doc/mod_wsgi*/README |grep /myapp 复制查询结果
vim /etc/httpd/conf.d/script.conf
Listen 8989
ServerName webapp0.example.com
WSGIScriptAlias / /var/www/webapp.wsgi
systemctl restart httpd
通过浏览器测试 http://webapp0.example.com:8989 是否返回动态页面
HTTP实验结束后,重启server0后验证,如果没有问题,在 foundation上执行 rht-vmctl reset all 恢复一次虚拟机,避免干扰后面的实验
====================================================================================================
14. 在 server0 上创建一个脚本,名为 /root/mkusers , 同时满足下列要求:
此脚本能实现为系统 server0 创建本地用户, 这些用户的用户名来自一个包含用户名列表的文件。
此脚本要求提供一个参数,此参数就是包含用户名列表的文件
如果没有提供参数,此脚本应该给出下面的提示信息 Usage: /root/mkusers 然后退出并返回相应的值
如果提供一个不存在的文件名,此脚本应该给出下面的提示信息 Input file not found 然后退出并返回相应的值
创建的用户登录 shell 为 /bin/false
此脚本不需要为用户设置密码
用户列表文件内容如下,请自行创建用户列表文件
tom
jerry
alias
natasha
mario
harry
vim /root/makeusers
#!/bin/bash
if [ $# -ne 1 ]; then
echo 'Usage: /root/makeusers '
exit 1
fi
if [ ! -f "$1" ]; then
echo "Input file not found"
exit 2
fi
while read line
do useradd -s /bin/false $line
done < $1
在 server0 上创建一个名为 /root/script.sh 的脚本, 让其提供下列特性:
当运行 /root/script.sh all,输出为 none
当运行 /root/script.sh none,输出为 all
当没有任何参数或者参数不是 all 或者 none时, 其错误输出产生以下的信息:all|none
vim /root/script.sh
#!/bin/bash
case $1 in
all)
echo “none” ;;
none)
echo “all” ;;
*)
echo “all|none” ;;
esac
chmod +x /root/script.sh
-----------------------------------------------------------------------------------------------------------
15. 配置iSCSI服务端
配置 server0 使其能够对外提供 iSCSI 服务,磁盘名为 iqn.2018-03.com.example:server0 并符合下列要求:
服务端口为 3260
使用 iscsi_data 作其后端卷,其大小为 3G,此服务只能被 desktop0.example.com 使用
yum -y install targetcli
systemctl enable target
systemctl start target
firewall-cmd --permanent --add-port=3260/tcp
firewall-cmd --reload
fdisk /dev/vdb
pvcreate /dev/vdb1
vgcreate –s 1M iscsi_data /dev/vdb1
lvcreate -l 3072 -n iscsi_data iscsi_data
使用命令进入服务器配置管理
targetcli
/backstores/block/ create iscsi_data /dev/iscsi_data/iscsi_data
/iscsi create iqn.2018-03.com.example:server0
/iscsi/iqn.2018-03.com.example:server0/tpg1/acls/ create iqn.2018-03.com.example:server0
/iscsi/iqn.2018-03.com.example:server0/tpg1/luns create /backstores/block/iscsi_data
/iscsi/iqn.2018-03.com.example:server0/tpg1/portals create 172.25.0.11
=====================================================================================================
16. 配置 iSCSI 的客户端
配置 desktop0 使其能连接在 server0 上提供的 iqn.2018-03.com.example:server0 并符合以下要求:
iSCSI 设备在系统启动的期间自动加载
块设备 iSCSI 上包含一个大小为 1900 MiB 的分区,并格式化为 xfs
此分区挂载在 /mnt/data 上,同时在系统启动的期间自动挂载
systemctl enable iscsi
systemctl start iscsi
vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2018-03.com.example:server0
man iscsiadm 查找EXAMPLES
iscsiadm --mode discovery --type sendtargets --portal 172.25.0.11 --discover
iscsiadm --mode node --targetname iqn.2018-03.com.example:server0 --portal 172.25.0.11:3260 --login
fdisk /dev/sda 分 1900M
partprobe
mkfs.xfs /dev/sda1
通过 blkid 找到 sda1 的 UUID xxxxxxxxxxxxxxxxxxxx
vim /etc/fstab
UUID=xxxxxxxxxxxxxxxxxxxx /mnt/data xfs defaults,_netdev 0 0
重启检查时,如果发生无法关机的情况,可以考虑强制关闭客户端,一定记得重启检查避免客户端无法正常启动
==============================================================================================================
17. 配置一个数据库
在 server0 上创建一个 MariaDB 数据库, 名为 Production 并符合以下条件:
production 数据库应该包含来脚本文件的内容
数据库备份的脚本文件的 URL http://classroom.example.com/materials/mariadb/inventory.dump
数据库只能被 localhost 访问。
除了root用户,此数据库只能被用户 Luigi 查询。此用户密码为 redhat
root 用户的密码为 redhat,并且不允许空密码登录。
yum groupinstall mariadb mariadb-client -y
vim /etc/my.cnf #由于只能被本地访问,所以要修改配置文件
[mysqld]
skip-networking=1
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation #通过这个命令进行 root 密码的设置,除了第一个选项直接回车后,输入 root 密码之外,其他的选项默认选 Y
mysql -u root #测试是否空密码可以登录,如果报错则设置成功
mysql -u root -p
CREATE DATABASE Production; #创建数据库
CREATE USER Luigi@localhost IDENTIFIED BY 'redhat'; #创建查询用户
GRANT SELECT ON Production.* to Luigi@localhost; #设置权限
wget http://classroom.example.com/materials/mariadb/inventory.dump
mysql -u root -p Production < /root/inventory.dump
数据库查询
在系统 server0 上使用数据库 Production 并使用相应的 SQL 查询以回答下列问题:
查询设备类型为 Networking 的 销售人员的名字和电话是多少?