1/14(SELINUX、构建WEB、构建FTP、防火墙策略管理、管理运行级别/模式)

一、常用的网络工具
1.查看IP地址

ip address show
ip a s
2.临时添加IP地址
ip address add 192.168.10.1/24 dev eth0
ip a s #查看IP地址
3.删除IP地址
ip address del 192.168.10.1/24 dev eth0
ip a s #查看IP地址

二、ping 命令,测网络连接
格式:ping -c 包个数 IP地址
例如:ping -c 2 192.168.4.7
ping -c 3 192.168.4.207

一、SELinux
1.SELinux的运行模式
enforcing(强制)、permissive(宽松)
disabled(彻底禁用)

2.切换运行模式
临时切换:setenforce 1或0
固定配置:/etc/selinux/config 文件

例如:getenforce #查看当前运行模式
setenforce 0 #修改当前运行模式(临时修改)
getenforce
vim /etc/selinux/config (永久修改需要重启)
SELINUX=permissive

二、破解root密码思路
1.重启系统进入恢复模式(救援模式)
root
开启虚拟机,在界面按e键
将ro修改为rw
最后,空格输入 rd.break
按 ctrl + x 启动,会看到switch_root:/#
2.切换到硬盘操作系统环境
#chroot /sysroot #切换环境,切换到硬盘操作系统的环境
3.重新设置root的密码
sh-4.2# echo 1 | passwd --stdin root
4.如果SELinux是强制模式,才需要重设SELinux策略(其他模式不需要做此操作)
sh-4.2# vim /etc/selinux/config #查看SELinux开机的运行模式
sh-4.2# touch /.autorelabel #让SELinux失忆
5.强制重启系统完成修复
sh-4.2# reboot -f

三、构建WEB服务
提供Web服务的软件:httpd、Nginx、tomcat
1.安装软件包
yum -y install httpd
2.运行提供Web服务程序
》/etc/resolv.conf #清空此文件内容
/usr/sbin/httpd #绝对路径运行程序
pgrep -l httpd #查看进程信息
3.书写一个页面文件
vim /var/www/html/index.html 保罗乔治
4.浏览器访问测试
curl http://192.168.4.7
curl 192.168.4.7

如果程序无法运行:
yum -y reinstall httpd

四、构建FTP服务
实现FTP服务功能的软件:vsftpd
默认共享数据的主目录:/var/ftp/

1.安装软件包
yum -y install vsftpd
2.运行程序
/usr/sbin/vsftpd #绝对路径运行程序
pgrep -l httpd #查看进程信息
3.访问测试
curl ftp://192.168.4.7

五、防火墙策略的管理
管理工具:firewall-cmd、firewall-config
public:仅允许访问本机的ssh、dhcp、ping服务
trusted:允许任何访问
block:拒绝任何来访请求,明确拒绝客户端
drop:丢弃任何来访的数据包,不给任何回应

六、防火墙默认区域的修改:
A:firewall-cmd --get-default-zone #查看默认区域
B:curl http://192.168.4.7 #失败
curl ftp://192.168.4.7 #失败
ping -c 192.168.4.7 #成功
A:firewall-cmd --set-default-zone=trusted
B:curl http://192.168.4.7 #成功
curl ftp://192.168.4.7 #成功

七、防火墙public区域添加规则
A:firewall-cmd --set-default-zone=public
firewall-cmd --zone=public --add-service=http
firewall-cmd --zone=public --list-all
B:curl http://192.168.4.7 #成功
curl ftp://192.168.4.7 #失败

A:firewall-cmd --zone=public --add-service=ftp
firewall-cmd --zone=public --list-all
B:curl http://192.168.4.7 #成功
curl ftp://192.168.4.7 #成功

八、防火墙public区域添加规则(永久)(–permanent)
firewall-cmd --reload #加载防火墙永久策略
firewall-cmd --zone=public --list-all
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=ftp
firewall-cmd --zone=public --list-all
firewall-cmd --reload #加载防火墙永久策略
firewall-cmd --zone=public --list-all

九、关闭防火墙
systemctl stop firewalld #停止防火墙
systemctl disable firewalld #禁止开机自启动

yum -y install httpd
》 /etc/resolv.conf #清除文件内容
killall httpd #杀死手动启动的httpd
systemctl restart 服务名 #重起服务
systemctl start 服务名 #开启服务
systemctl stop 服务名 #停止服务
systemctl status 服务名 #查看服务当前的状态
systemctl enable 服务名 #设置服务开机自启动
systemctl disable 服务名 #设置服务禁止开机自启动
systemctl is-enabled 服务名 #查看服务是否开机自启

十、管理运行级别
RHEL6:运行级别 300
0:关机 0个服务
1:单用户模式(基本功能的实现,破解Linux密码) 50个服务
2:多用户字符界面(不支持网络) 80个服务
3:多用户字符界面(支持网络)服务器默认运行级别 100个服务
4:未定义 0个服务
5:图形界面 300个服务
6:重起 0个服务
切换运行级别:init 数字

十一、RHEL7:运行模式(运行级别)
字符模式:multi-user.target
图形模式:graphical.target
当前直接切换到字符模式
]# systemctl isolate multi-user.target #相当于原来的init 3
当前直接切换到图形模式
]# systemctl isolate graphical.target #相当于原来的init 5

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值