RHCE_习题详解

    ---------------------------------------------------------------------------------------------------------

RHCE习题详解

---------------------------------------------------------------------------------------------------------

//---n准备工作

'a'.iptables

1>chkconfig iptables on

2>iptables -F

3>service iptables save

4>service iptables restart

//[注]:考试时,将所有规则清空,默认策略为ACCEPT;将题目中要【阻止】的条目,写入iptables,及时service iptables save

'b'.配置yum源

1>vim /etc/yum.repos.d/test.repo

[test]
name=test
baseurl=http://instructor.example.com/pub/rhel6/dvd
enabled=1
gpgcheck=0

'c'.配置服务要注意

1> yum -y install package

2> chkconfig [service] on

3> 修改配置文件

4> nfs/samba/ftp //注意,适当修改文件夹的权限;SELinux 上下文,setsebool值;

//-----题目

'a'本地域:192.168.0.0/24
'b'敌对域:192.168.1.0/24

1>selinux改为强制

1.vim /etc/sysconfig/selinux --> SELINUX=enforcing
2.getenforce //如果为0,则执行第三步
3.setenforce 1

2>ip转发

1/etc/sysctl.conf --> net.ipv4.ip_forward = 1
2.sysctl -p

3>编制脚本:输入"bar" -> "foo";输入"foo" --> "bar";其他输出"/root/script bar|foo"

#!/bin/bash
#
function main()
{
if [ $# -eq 1 ] ; then {

if [ "$1" = "bar" ] ; then
echo "foo"
return
elif [ "$1" = "foo" ] ; then
echo "bar"
return
fi
}
fi

echo "/root/script foo|bar"

}
main $@

4>在系统启动时,向内核传递参数sysvctl=1

1/boot/grub/grub.conf

kernel /vmlinuz-2.6.32-71.el6.x86_64 ro root=/dev/mapper/vgsrv-root rd_LVM_LV=vgsrv/root rd_LVM_LV=vgsrv/swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet 'sysvctl=1'

5>自动挂载光盘映像

1/etc/fstab

/tmp/vmware.iso /mnt/diskimg iso9660 loop,ro 0 0

2.mount -a

6>不允许natasha使用crontab

1/etc/cron.deny ---> natasha

'验证:'
a> su - natasha;

b> crontab -e //提示无法使用;注意,此时root仍然可以执行 crontab -u natasha -e

7>配置apache:到ftp服务器下载主页文件station.html,架设网站station.example.com
只允许本地域访问,harry可以对网站文件夹读写

-----'注意事项'

1.yum -y install httpd

2.chkconfig httpd on


-----'httpd.conf'

1.NameVirtualHost *:80

2.<VirtualHost *:80>

DocumentRoot /var/www/html
ServerName station.example.com

<Directory "/var/www/html">
Options Indexes MultiViews FollowSymLinks
Order allow,deny
Allow from 192.168.0.0/24 //只允许本地域访问,有时会失效 -----> 还可以使用iptables[推荐],只不过iptables禁止所有网站,因为--dport 80
</Directory>

</VirtualHost>

-----------

3.setfacl -m u:harry:rw /var/www/html //harry可以读写

8>配置apache:到ftp下载主页文件,架设www1.example.com
网站内有 secret目录,只允许本机用户访问

-----'httpd.conf'

1.NameVirtualHost *:80

2.<VirtualHost *:80>
DocumentRoot /var/www/test
ServerName www1.example.com

<Directory "/var/www/test/secret">
AuthName "test"
AuthType basic
AuthUserFile /etc/httpd/conf/.users
require valid-user
</Directory>
</VirtualHost>

//----只允许本机用户访问

解决方案1>

1.cat /etc/shadow | cut -d : -f 1-2 > /etc/httpd/conf/.users
//此时,本地用户登录登录www1.example.com/secret/ 时,输入的密码和登录linux相同

解决方案2>

1.htpasswd -cm /etc/httpd/conf/.users harry

2.htpasswd -m /etc/httpd/conf/.users natasha
--------------------

9>、ftp 服务器,匿名下载,'<'默认:本地用户可以上传下载'>',但不允许连接到其它目录,不允许其他域访问

-----'注意事项'

1.yum -y install vsftpd

2.chkconfig vsftpd on

------'/etc/vsftpd/vsftpd.conf

1.chroot_local_user=YES //但不允许连接到其它目录

------'SELinux'

1.setsebool -P ftp_home_dir on //ftp_home_dir:使得本地用户可以登录ftp

2.setsebool -P allow_ftpd_full_access //all_ftpd_full_access:包括ftp_home_dir

//'只要上传/下载,则必须' allow_ftpd_full_access

-----'不允许其他域访问'

1.iptables -A INPUT ! -s 192.168.0.0/24 -p tcp --dport 20 -j REJECT

2.iptables -A INPUT ! -s 192.168.0.0/24 -p tcp --dport 21 -j REJECT

-----------

10>nfs到出/common,只允许本地域主机 以 'rw' 挂载

- --'注意事项'

1.yum -y install nfs-utils

2.chkconfig nfs on

----'/etc/exports'

1./common 192.168.0.0/24(rw,sync)

----'开放/common 权限‘

1.chmod o+w /common //开放文件底层权限

-----------

11>samba 建/common 共享,共享名 comm,主机属于 staff 工作组,只允许本地域的机器'读写',
不允许 cracker 域使用

--'注意事项'

1.yum -y install samba

2.chkconfig smb on


----'/etc/samba/smb.conf'

Workgroup staff


[comm]
comment = test
path = /common
public = yes //public=yes,即使security=user,登录该共享目录也不需要输入密码
writable = yes //writable=yes:所有人可写; write list=natasha:只有部分人可写; 这两项不要同时出现
hosts allow = 192.168.0. 127. //注意格式,

//允许127.--->使得可以通过smbclient //localhost/comm -U harry访问

----'SELinux'

1.mkdir /common

2.chcon -t samba_share_t /common

----'放开文件权限'

1.chmod o+w /common //允许本地域的机器'读写'

----------------


12>SMTP 服务器,不允许 cracker 域访问

--'注意事项'

1.yum -y install postfix

2.chkconfig postfix on

---'查看postfix监听的ip地址===》决定哪些ip域可以向本机发送邮件‘

1.netstat -nat | grep 25

tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN

//127.0.0.1:25 --> 只能本机给自己发送邮件,无法收到其他ip主机发送的邮件

---'/etc/postfix/main.cf'

1.inet_interface=all //必须=========

2.myhostname = server4.example.com //可选

3.mynetworks = 192.168.0.0/24, 127.0.0.0/8 //可选

---'查看是否‘

1.netstat -nat | grep 25

tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN

//0.0.0.0.0:25,则接收任何ip主机发送的邮件


---'IPtables --> 不允许 cracker 域访问'

1.iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 25 -j REJECT

2.---------------------------------------udp---------------------

3.service iptables save //保存iptables规则

4.service iptables restart

--------------

13>SSH服务只允许,本地域访问

---'iptables'

1.iptables -A INPUT ! -s 192.168.0.0/24 -p tcp --dport 22 -j REJECT

2.service iptables save //保存

3.service iptables restart

----------

14>iscsi 挂载,并自动挂载到/mnt/abc

---'注意‘ ----->' //重启电脑时,先退出iscsi: iscsiadm -m node -T target -p 192.168.0.254 -u //暂时退出iscsi

1.yum search iscsi ---> iscsi-initiator-utils

2.yum -y install iscsi-initiator-utils

3.chkconfig iscsi on

4.chkconfig iscsid on

---'操作'

1.iscsiadm -m discovery -t st -p 192.168.0.254 //查找target

2.iscsiadm -m node -T 复制上面的target -p 192.168.0.254 -l //挂载服务端的iscsi硬盘

3.fdisk -cu /dev/sda //分区 sda1

4.mkfs.ext4 /dev/sda1 //格式化

5.UUID=uuid /mnt/abc/ ext4 '_netdev' 0 0 //_netdev$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

------------

15> 邮件别名 marry的发给root

----'/etc/aliases'

mary: root

----"操作“

1.newaliases


------------------------------------------------------------------


"辅助软件"

1---'邮件查看mutt'


































































//---以 root 用户操作

1>设置 用户 及 组 manager 对目录/home/cnrts 有读写执行权限,其它人无任何权限,

【并且用户在此目录下创建文件自动继承属组权限 = 任何用户在此目录下创建的文件的组用户都是:manager】

1.mkdir /home/cnrts

2.chgrp manager /home/cnrts

3.chmod 2770 /home/cnrts //2:sgid,使得'任何用户在此目录下创建的文件的组用户都是:manager'; 继承[父目录]属组权限
我在IBM工作,可以为大家内部推荐IBM各种职位 IBM全球职位尽在以下链接(请在浏览器中打开,QQ/微信 会阻止): http://ibmreferrals.com/ 很乐意为感兴趣的小伙伴分享:我的面试经验^_^ 如需咨询,请邮件发送以下邮箱,有问必回 1026096425@qq.com
原文地址:https://www.cnblogs.com/jackydalong/p/2408833.html