运维之红帽工程师篇-----1.selinux ,alias别名,聚合连接,ipv6,web,防火墙

来源:互联网 发布:淘宝网武笙缘太极服 编辑:程序博客网 时间:2024/05/20 05:26

ONE DAY

总结笔记:

1.selinux

[root@server0 ~]# getenforce     #查看当前状态

[root@server0 ~]# setenforce 0   #当前关闭SELinux

[root@server0 ~]# vim /etc/selinux/config   #永久修改

SELINUX=permissive

2.alias

[root@server0 ~]# vim /root/.bashrc         #针对root用户

[root@server0 /]# vim /home/tom/.bashrc      #针对tom用户

[root@server0 /]# vim /etc/bashrc            #针对全体用户

[root@server0 /]# grep haha /etc/bashrc 

3.聚合链接

输入  /example    #所有的帮助信息中查找example

                             输入  n           #跳转匹配

[root@desktop0 ~]# man teamd.conf      

[root@server0 /]# nmcli connection add type team autoconnect yes  ifname team0 con-name team0 config '{"runner": {"name": "activebackup"}}'   #man  teamd.conf

[root@server0 /]# nmcli connection add type team-slave ifname eth1 con-name team0-1 autoconnect yes master team0 

[root@server0 /]# nmcli connection add type team-slave ifname eth2 con-name team0-2 autoconnect yes master team0 

[root@server0 /]# nmcli connection modify team0 ipv4.method manual ipv4.addresses 192.168.1.1/24 connection.autoconnect yes 

[root@server0 /]# nmcli connection up team0

[root@server0 /]# nmcli connection up team0-1

[root@server0 /]# nmcli connection up team0-2

[root@server0 /]# ifconfig team0     

[root@server0 /]# nmcli connection delete team0 

[root@server0 /]# nmcli connection delete team0-1

[root@server0 /]# nmcli connection delete team0-2

4.配置IPv6

[root@server0 /]# nmcli connection modify 'System eth0' ipv6.method manual ipv6.addresses 2003:ac18::305/64 connection.autoconnect  yes

[root@server0 /]# nmcli connection up 'System eth0'

5.搭建web服务

1.安装服httpd/vsftpd

2.启动服务httpd,设置为开机自起

[root@server0 /]# systemctl start httpd/vsftpd

server0 /]# systemctl enable httpd/vsftpd

[root@[root@server0 ~]# firefox http://127.0.0.1    firefox ftp://127.0.0.1

6.防火墙

# firewall-cmd --list-all                   #查看当前默认区域信息

firewall-cmd --set-default-zone=public/trusted/block/drop/      #设置默认区域

#firewall-cmd  --zone=block  --add-source=172.25.0.11   #默认区域修改

firewall-cmd --permanent --add-service=http            #开启服务http~~~

# firewall-cmd --permanent --add-service=ftp              #~~~~

 firewall-cmd --permanent --add-forward-port=port=5423:proto=tcp:toport=80      #端口转发

# firewall-cmd --reload     #重新加载

# firewall-cmd --list-all

 

 正式笔记

系统安全保护

1.SELinux安全机制

• Security-Enhanced Linux

– 美国NSA国家安全局主导开发,一套增强Linux系统安

全的强制访问控制体系

– 集成到Linux内核(2.6及以上)中运行

– RHEL7基于SELinux体系针对用户、进程、目录和文件

提供了预设的保护策略,以及管理工具

SELinux运行模式的切换

• SELinux的运行模式

– enforcing(强制)permissive(宽松)

– disabled(彻底禁用)

• 切换运行模式

– 临时切换:setenforce 1|0

– 固定配置:/etc/selinux/config 文件

[root@server0 ~]# getenforce     #查看当前状态

Enforcing

[root@server0 ~]# setenforce 0   #当前关闭SELinux

[root@server0 ~]# getenforce 

Permissive

[root@server0 ~]# vim /etc/selinux/config   #永久修改

SELINUX=permissive

###################################################

2.• 定义新的别名

– alias 别名名称= '实际执行的命令行'

• 取消已设置的别名

– unalias [别名名称]

用户初始化文件

• 影响指定用户的 bash 解释环境

– ~/.bashrc,每次开启 bash 终端时生效

• 影响所有用户的 bash 解释环境

 /etc/bashrc,每次开启 bash 终端时生效

[root@server0 ~]# useradd tom

[root@server0 ~]# useradd natasha

[root@server0 ~]# vim /root/.bashrc         #针对root用户

[root@server0 ~]# grep 'hi' /root/.bashrc

alias hi='echo hello'

[root@server0 /]# vim /home/tom/.bashrc      #针对tom用户

[root@server0 /]# grep 'myls' /home/tom/.bashrc 

alias myls='ls -lhd'

[root@server0 /]# vim /etc/bashrc            #针对全体用户

[root@server0 /]# grep haha /etc/bashrc 

alias  haha='echo xixi'

[root@server0 /]# su - tom

[tom@server0 ~]$ 执行  himylshaha

[root@server0 /]# su - natasha

[natasha@server0 ~]$ 执行  himylshaha

##################################################

3.配置聚合连接 HSRP   活跃路由       备份路由     虚拟路由  

               聚合连接    eth1     eth2

                      team0  

[root@desktop0 ~]# man teamd.conf

                            输入  /example    #所有的帮助信息中查找example

                             输入  n           #跳转匹配

[root@desktop0 ~]# man teamd.conf      

[root@server0 /]# nmcli connection add type team autoconnect yes  ifname team0 con-name team0 config '{"runner": {"name": "activebackup"}}'   #man  teamd.conf

[root@server0 /]# nmcli connection add type team-slave ifname eth1 con-name team0-1 autoconnect yes master team0 

[root@server0 /]# nmcli connection add type team-slave ifname eth2 con-name team0-2 autoconnect yes master team0 

[root@server0 /]# nmcli connection modify team0 ipv4.method manual ipv4.addresses 192.168.1.1/24 connection.autoconnect yes 

[root@server0 /]# nmcli connection up team0

[root@server0 /]# nmcli connection up team0-1

[root@server0 /]# nmcli connection up team0-2

[root@server0 /]# ifconfig team0     

[root@server0 /]# nmcli connection delete team0 

[root@server0 /]# nmcli connection delete team0-1

[root@server0 /]# nmcli connection delete team0-2

##################################################

4.配置IPv6地址

 IPv4 地址表示32个二进制位,点分隔的十进制数

– 例如:172.25.0.11127.0.0.1

• IPv6 地址表示128个二进制位,冒号分隔的十六进制数

– 每段内连续的前置 可省略、连续的多个 可简化为 ::

– 例如:2003:ac18:0000:0000:0000:0000:0000:0305

           2003:ac18::305

 

虚拟机server0

[root@server0 /]# nmcli connection modify 'System eth0' ipv6.method manual ipv6.addresses 2003:ac18::305/64 connection.autoconnect  yes

[root@server0 /]# nmcli connection up 'System eth0'

虚拟机desktop

[root@desktop0 /]# nmcli connection modify 'System eth0' ipv6.method manual ipv6.addresses 2003:ac18::306/64 connection.autoconnect  yes

[root@desktop0 /]# nmcli connection up 'System eth0'

测试

[root@server0 /]# ping6 2003:ac18::306

######################################################

5.搭建Web服务

服务端:server

1.安装服务端程序, httpd

2.启动服务httpd,设置为开机自起

[root@server0 /]# systemctl start httpd

[root@server0 /]# systemctl enable httpd

 前提:关闭真机所有的火狐浏览器 

3.测试

[root@room9pc14 桌面]# ssh -X root@172.25.0.11

[root@server0 ~]# firefox http://127.0.0.1

4.书写一个页面文件

   网页文件默认存放位置:/var/www/html

   网页文件默认名称:index.html

[root@server0 ~]# vim /var/www/html/index.html 

<marquee><font color=red><h1>hahaxixihehelele

[root@server0 ~]# firefox 127.0.0.1

搭建基本FTP服务

1.服务端server,安装可以提供ftp服务的软件

[root@server0 ~]#  yum -y install vsftpd 

2.启动服务vsftpd,设置为开机自起

[root@server0 ~]# systemctl start  vsftpd 

[root@server0 ~]# systemctl enable  vsftpd 

3.测试

[root@server0 ~]# firefox ftp://127.0.0.1

4.FTP服务默认属性: 

        默认FTP共享路径:/var/ftp

#####################################################

6.firewall防火墙

 系统服务:firewalld

• 管理工具:firewall-cmd(命令)、firewall-config(图形工具)

预设安全区域

• 根据所在的网络场所区分,预设保护规则集

 public:仅允许访问本机的sshd等少数几个服务

– trusted:允许任何访问

– block:阻塞任何来访请求

– drop:丢弃任何来访的数据包

• 配置规则的位置

– 运行时(runtime)

– 永久(permanent)

#####################################################

RHEL7判断规则:

  1.查看客户端数据包中 IP地址,自己所有区域中,是否对该源IP地址设置策略,如果有一个区域设置策略,则进入该区域

  2.查看客户但数据从本机那一张网卡进来,自己所有区域中,哪一个区域有对该网卡的策略

  3.以上均不满足 进入默认区域

###################################################

默认区域修改

虚拟机server0

[root@server0 ~]# firewall-cmd --list-all   #查看默认区域信息1

虚拟机desktop0

[root@desktop0 ~]# ping 172.25.0.11        #可以通信

虚拟机server0

[root@server0 ~]# firewall-cmd --set-default-zone=block 2

[root@server0 ~]# firewall-cmd --list-all

虚拟机desktop0

[root@desktop0 ~]# ping 172.25.0.11    #不可以通信 ,有回应

虚拟机server0

[root@server0 ~]# firewall-cmd --set-default-zone=drop

[root@server0 ~]# firewall-cmd --list-all

虚拟机desktop0

[root@desktop0 ~]# ping 172.25.0.11    #不可以通信 ,没有回应

#####################################################

firewall应用模式:

模式1(宽松):默认区域trusted,将想要拒绝的IP直接放入block区域

#firewall-cmd  --zone=block  --add-source=172.25.0.113

模式2(严格):默认区域block,将想要允许的IP直接放入trusted区域

添加IP命令:

#####################################################

认区域的修改,不需要添加permanent选项,默认区域修改,默认是永久

虚拟机server0:

[root@server0 ~]# firewall-cmd --set-default-zone=public 

[root@server0 ~]# firewall-cmd --list-all

虚拟机desktop0

[root@desktop0 ~]# firefox 172.25.0.11       #不可以

[root@desktop0 ~]# firefox ftp://172.25.0.11 #不可以

虚拟机server0:

# firewall-cmd --set-default-zone=public

#firewall-cmd  --zone=block  --add-source=172.25.0.11

firewall-cmd --permanent --add-service=http4

# firewall-cmd --permanent --add-service=ftp

firewall-cmd --reload     #重新加载5

# firewall-cmd --list-all

虚拟机desktop0

[root@desktop0 ~]# firefox 172.25.0.11        #可以http

[root@desktop0 ~]# firefox ftp://172.25.0.11  #可以ftp

##################################################

防火墙的端口转发功能

– 访问 server0 的本地端口5423将被转发到80

– 上述设置必须永久有效

虚拟机server0:

[root@server0 ~]# firewall-cmd --permanent --add-forward-port=port=5423:proto=tcp:toport=80 

[root@server0 ~]# firewall-cmd --reload 

[root@server0 ~]# firewall-cmd --list-all

虚拟机desktop0:

[root@desktop0 ~]# firefox 172.25.0.11:5423

##################################################

阅读全文
0 0