[内容] Linux SELinux 状态的设置

内容一:SELinux 的状态

1) Disabled:完全关闭 SELinux
2) Permissive:即使违反了策略也依旧可以执行,但是违反策略的记录会被记录在日志中
3) Enforcing:如果违反了策略就不能之行

内容二:永久切换 SELinux 状态

2.1 将 SELinux 永久切换至 Disabled 状态

2.1.1 修改 SELinux 配置文件
# vim /etc/selinux/config

将以下内容:

......
SELINUX=......
......

修改为:

......
SELINUX=disabled
......
2.1.2 重启系统
# reboot
2.1.3 显示 SELinux 状态
# getenforce 
Disabled

2.2 将 SELinux 永久切换至 Permissive 状态

2.2.1 修改 SELinux 配置文件
# vim /etc/selinux/config

将以下内容:

......
SELINUX=......
......

修改为:

......
SELINUX=permissive
......
2.2.2 重启系统
# reboot
2.2.3 显示 SELinux 状态
# getenforce 
Permissive

2.3 将 SELinux 永久切换至 Enforcing 状态

2.3.1 修改 SELinux 配置文件
# vim /etc/selinux/config

将以下内容:

......
SELINUX=......
......

修改为:

......
SELINUX=enforcing
......
2.3.2 重启系统
# reboot
2.3.3 显示 SELinux 状态
# getenforce 
Enforcing

内容三:临时切换 SELinux 状态

3.1 临时切换到 Permissive 状态

3.1.1 临时切换到 Permissive 状态
# setenfoce 0


注意:
1) 系统重启后失效
2) 只能从 Enforcing 状态切换到 Permissive 状态

3.1.2 显示 SELinux 状态
# getenforce 
Permissive

3.2 临时切换到 Enforcing 状态

3.2.1 临时切换到 Enforcing 状态
# setenfoce 1


注意:
1) 系统重启后失效
2) 只能从 Permissive 状态切换到 Enforcing 状态

3.2.2 显示 SELinux 状态
# getenforce 
Enforcing

[工具] Shell 检测服务器某个端口有没有启动

介绍

基本信息

作者:朱明宇
名称:检测服务器某个端口有没有启动
作用:检测服务器某个端口有没有启动

使用方法

1. 在此脚本的分割线内写入相应的内容
2. 给此脚本添加执行权限
3. 执行此脚本
4. 如果被检测的端口被启动则会被记录在指定文件里

脚本分割线里的变量

1. checkport=’7111′ #被检测的端口
2. logfile=’checkportlog.txt’ #记录文件

脚本

#!/bin/bash

####################### Separator ########################
checkport='7111'
logfile='checkportlog.txt'
####################### Separator ########################

a=`/sbin/ss -ntulap | grep udp | grep $checkport | awk '{print $7}' | awk -F'"' '{print $2}'`

if [ -n "$a" ];then
       echo `date` >> $logfile
       echo $checkport >> $logfile
       echo `/sbin/ss -ntulap | grep udp | grep $checkport | awk '{print $7}' | awk -F'"' '{print $2}'` >> $logfile
       echo >> $logfile
fi