10.19 iptables规则备份和恢复
备份iptables规则,名字自定义 iptables-save > /tmp/ipt.txt
恢复备份的规则 iptables-restore < /tmp/ipt.txt
10.20 firewalld的9个zone
关闭iptables
systemctl disable iptables.service
systemctl stop iptables.service
打开firewalld
systemctl enable firewalld.service
systemctl start firewalld.service
firewall-cmd --get-zones 查看所有zone
firewall-cmd --get-default-zone 查看默认的zone
10.21 firewalld关于zone的操作
firewall-cmd --set-default-zone=work 设定默认zone
firewall-cmd --get-zone-of-interface=ens33 查看指定网卡的zone
firewall-cmd --zone=dmz --add-interface=ens37 给指定网卡设置zone
firewall-cmd --zone=public --add-interface=lo
firewall-cmd --zone=block --change-interface=ens37 更改指定网卡的zone
firewall-cmd --zone=block --remove-interface=ens37 删除指定网卡的zone
firewall-cmd --get-active-zones 查看系统所有网卡所在的zone
10.22 firewalld关于service的操作
firewall-cmd --get-services 查看所有的service
firewall-cmd --list-services 查看当前zone下有哪些service
firewall-cmd --zone=public --list-services
firewall-cmd --zone=public --add-service=http 把http增加到public zone 下
firewall-cmd --zone=public --add-service=ftp --permanent 写入到配置文件里
cat /etc/firewalld/zones/public.xml
zone的配置文件模板
ls /usr/lib/firewalld/zones/ zone的配置文件模板
ls /usr/lib/firewalld/services/ service的配置文件模板
cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services/ 拷贝services的配置文件
vi /etc/firewalld/services/ftp.xml 更改端口
cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/ 拷贝zone的配置文件
vim /etc/firewalld/zones/work.xml 增加 service
firewall-cmd --reload 重新加载
firewall-cmd --zone=work --list-services 查看services
10.23 linux任务计划cron
cat /etc/crontab
crontab -e 编辑一个任务计划
crontab -l 查看当前用户的任务计划
crontab -r 删除任务计划
crontab -u 指定用户
1-5 指定一个范围
*/2 被2整除的数,例子里面是双月
2,5代表 第二周和第五周
systemctl start crond.service 启动crond 服务
10.24 chkconfig工具
chkconfig --list
chkconfig --level 234 network off 关闭服务的启动级别
chkconfig --level 234 network on 开启服务的启动级别
chkconfig --del network 删除系统服务
chkconfig --add network 添加系统服务
cp network 123 拷贝一个服务脚本
脚本里面包括这两行才会被识别
# chkconfig: 2345 10 90
# description: Activates/Deactivates all network interfaces configured to \
# start at boot time.
chkconfig --add 123
10.25 systemd管理服务
systemctl list-units --all --type=service 列出系统所有的服务
systemctl enable crond.service // 让某个服务开机启动(.service 可以省略)
systemctl disable crond.service // 设为开机不启动
systemctl status crond.service // 查看服务状态
systemctl start crond.service // 启动某个服务
systemctl stop crond.service // 停止某个服务
systemctl is-enabled crond //查看某个服务是否开机启动
/usr/lib/systemd/system/crond.service 启动脚本的实际位置
启动的时候会创建一个软链接
10.26 unit介绍
/usr/lib/systemd/system
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
systemctl is-enabled crond.service 查看服务是否为enabled
10.27 target介绍
systemctl list-unit-files --type target 列出系统中所有的target
systemctl list-dependencies multi-user.target 查看target下有哪些unit
systemctl get-default 查看系统的默认target
systemctl set-default multi-user.target 设置默认
cat /usr/lib/systemd/system/sshd.service 看Install 部分
课堂笔记
一、iptables规则备份和恢复
二、firewalld的9个zone
三、firewalld关于zone的操作
四、firewalld关于service的操作
五、linux任务计划cron
六、chkconfig工具
七、systemd管理服务
八、unit介绍
九、target介绍
一、iptables规则备份和恢复
设定的防火墙规则只是保存在内存中,并没有保存到配置文件中,也就说当系统重启后以前设定的规则就没有了,所以
设定好规则后要先保存规则,以免重启后规则丢失。
[root@lanquark ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
//etc/sysconfig/iptables为iptables的配置文件
iptables规则备份、恢复
//插入一条演示用规则
[root@lanquark ~]# iptables A INPUT p tcp s 192.168.1.9 dport 22 j ACCEPT
[root@lanquark ~]# iptables nvL
Chain INPUT (policy ACCEPT 5 packets, 2173 bytes)
pkts bytes target prot opt in out source destination
53 3524 ACCEPT tcp * * 192.168.1.9 0.0.0.0/0 tcp dpt:22
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 28 packets, 2736 bytes)
pkts bytes target prot opt in out source destination
//保存规则
[root@lanquark ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@lanquark ~]# cat /etc/sysconfig/iptables
# Generated by iptablessave v1.4.21 on Thu Jun 14 22:12:34 2018
*nat
:PREROUTING ACCEPT [6:788]
:INPUT ACCEPT [6:788]
:OUTPUT ACCEPT [3:228]
:POSTROUTING ACCEPT [3:228]
A POSTROUTING s 192.168.2.0/24 o ens32 j MASQUERADE
COMMIT
# Completed on Thu Jun 14 22:12:34 2018
# Generated by iptablessave v1.4.21 on Thu Jun 14 22:12:34 20