备份linux
[root@localhost ~]# iptables-save > /tmp/ipt.bk
恢复bash
[root@localhost ~]# iptables-restore < /tmp/ipt.bk
打开firewalldssh
[root@localhost ~]# systemctl start firewalld.service [root@localhost ~]# systemctl enable firewalld.service
关闭iptablessocket
[root@localhost ~]# systemctl stop iptables.service [root@localhost ~]# systemctl disable iptables.service
firewalld有9个zone,默认zone为publictcp
查看全部zone工具
[root@localhost ~]# firewall-cmd --get-zones block dmz drop external home internal public trusted work
查看默认的zonerest
[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 | 拒绝流入的流量,除非与流出的流量相关 |
设置默认zonecode
[root@localhost ~]# firewall-cmd --set-default-zone=work success
查看指定网卡zonexml
[root@localhost ~]# firewall-cmd --get-zone-of-interface=ens33 work
给指定网卡设置zonedns
[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
查看全部的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
配置文件
[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小时
列出服务
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
查看全部服务
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 //检查服务是否开机启动
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
系统为了方便管理用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