10.19 iptables规则备份和恢复
备份
[root@localhost ~]# iptables-save > /tmp/ipt.bk
恢复
[root@localhost ~]# iptables-restore < /tmp/ipt.bk
10.20 firewalld的9个zone
打开firewalld
[root@localhost ~]# systemctl start firewalld.service
[root@localhost ~]# systemctl enable firewalld.service
关闭iptables
[root@localhost ~]# systemctl stop iptables.service
[root@localhost ~]# systemctl disable iptables.service
firewalld有9个zone,默认zone为public
查看所有zone
[root@localhost ~]# firewall-cmd --get-zones
block dmz drop external home internal public trusted work
查看默认的zone
[root@localhost ~]# firewall-cmd --get-default-zone
public
区域 | 默认规则策略 |
---|---|
trusted | 允许所有的数据包 |
home | 拒绝流入的流量,除非与流出的流量相关;而如果流量与ssh、mdns、ipp-client、amba-client与dhcpv6-client服务相关,则允许流量 |
internal | 等同于home区域 |
work | 拒绝流入的流量,除非与流出的流量数相关;而如果流量与ssh、ipp-client与dhcpv6-client服务相关,则允许流量 |
public | 拒绝流入的流量,除非与流出的流量相关;而如果流量与ssh、dhcpv6-client服务相关,则允许流量 |
external | 拒绝流入的流量,除非与流出的流量相关;而如果流量与ssh服务相关,则允许流量 |
dmz | 拒绝流入的流量,除非与流出的流量相关;而如果流量与ssh服务相关,则允许流量 |
block | 拒绝流入的流量,除非与流出的流量相关 |
drop | 拒绝流入的流量,除非与流出的流量相关 |
10.21 firewalld关于zone的操作
设置默认zone
[root@localhost ~]# firewall-cmd --set-default-zone=work
success
查看指定网卡zone
[root@localhost ~]# firewall-cmd --get-zone-of-interface=ens33
work
给指定网卡设置zone
[root@localhost ~]# firewall-cmd --zone=dmz --add-interface=ens33
The interface is under control of NetworkManager, setting zone to 'dmz'.
success
更改指定网卡的zone
[root@localhost ~]# firewall-cmd --zone=work --change-interface=ens33
The interface is under control of NetworkManager, setting zone to 'work'.
success
移除指定网卡的zone
[root@localhost ~]# firewall-cmd --zone=work --remove-interface=ens33
The interface is under control of NetworkManager, setting zone to default.
success
查看所有网卡的zone
[root@localhost ~]# firewall-cmd --get-active-zones
10.22 firewalld关于service的操作
查看所有的servies
[root@localhost ~]# firewall-cmd --get-services
查看当前zone下有哪些service
[root@localhost ~]# firewall-cmd --list-services
把http增加/移除到public zone下面
[root@localhost ~]# firewall-cmd --zone=public --add-service=http
[root@localhost ~]# firewall-cmd --zone=public --remove-service=http
zone的配置文件模板
ls /usr/lib/firewalld/zones/
更改配置文件,之后会在/etc/firewalld/zones目录下面生成配置文件
firewall-cmd --zone=public --add-service=http --permanent
需求:ftp服务自定义端口1121,需要在work zone下面放行ftp
[root@localhost ~]# cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services
[root@localhost ~]# vi /etc/firewalld/services/ftp.xml //port改为1121
<port protocol="tcp" port="1121"/>
[root@localhost ~]# cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/
[root@localhost ~]# vi /etc/firewalld/zones/work.xml //增加一行
<service name="ftp"/>
[root@localhost ~]# firewall-cmd --reload //重新加载
[root@localhost ~]# firewall-cmd --zone=work --list-services
10.23 linux任务计划cron
配置文件
[root@localhost ~]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
新增计划
[root@localhost ~]# crontab -e
查看已有计划
[root@localhost ~]# crontab -l
删除计划
[root@localhost ~]# crontab -r
指定用户计划
[root@localhost ~]# crontab -u root
备份,直接复制以下目录即可
/var/spool/cron/$username
格式
分范围0-59,时范围0-23,日范围1-31,月范围1-12,周1-7
可用格式1-5表示一个范围1到5
可用格式1,2,3表示1或者2或者3
可用格式*/2表示被2整除的数字,比如小时,那就是每隔2小时
10.24 chkconfig工具
列出服务
chkconfig --list
指定级别关闭
chkconfig network off //全部关闭
chkconfig --level 3 network off
chkconfig --level 345 network off
添加指定服务,让chkconfig可以管理
/etc/init.d/ //启动脚本放入此目录
chkconfig --del network
chkconfig --add network
10.25 systemd管理服务
查看所有服务
systemctl list-unit-files
查看所有service
systemctl list-units --all --type=service
几个常用的服务相关的命令
systemctl enable crond.service //让服务开机启动
systemctl disable crond //不让开机启动
systemctl status crond //查看状态
systemctl stop crond //停止服务
systemctl start crond //启动服务
systemctl restart crond //重启服务
systemctl is-enabled crond //检查服务是否开机启动
10.26 unit介绍
ls /usr/lib/systemd/system //系统所有unit,分为以下类型
service 系统服务
target 多个unit组成的组
device 硬件设备
mount 文件系统挂载点
automount 自动挂载点
path 文件或路径
scope 不是由systemd启动的外部进程
slice 进程组
snapshot systemd快照
socket 进程间通信套接字
swap swap文件
timer 定时器
unit相关的命令
systemctl list-units //列出正在运行的unit
systemctl list-units --all //列出所有,包括失败的或者inactive的
systemctl list-units --all --state=inactive //列出inactive的unit
systemctl list-units --type=service//列出状态为active的service
systemctl is-active crond.service //查看某个服务是否为active
10.27 target介绍
系统为了方便管理用target来管理unit
[root@localhost ~]# systemctl list-unit-files --type=target
查看指定target下面有哪些unit
[root@localhost ~]# systemctl list-dependencies multi-user.target
查看系统默认的target
[root@localhost ~]# systemctl get-default
设置默认的target
[root@localhost ~]# systemctl set-default multi-user.target
一个service属于一种类型的unit
多个unit组成了一个target
一个target里面包含了多个service
查看指定unit属于哪个target
[root@localhost ~]# cat /usr/lib/systemd/system/sshd.service
...
[Install]
WantedBy=multi-user.target