保存防火墙配置:
[root@ligen ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ 确定 ]
备份防火墙配置:
[root@ligen ~]# iptables-save > myipt.obt
[root@ligen ~]# cat myipt.obt
恢复备份:
[root@ligen ~]# iptables-restore < myipt.obt
开启firewall服务:
[root@ligen ~]# systemctl restart firewalld
[root@ligen ~]# systemctl enable firewalld
[root@ligen ~]# systemctl disable iptables
[root@ligen ~]# systemctl stop iptables
[root@ligen ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since 三 2019-04-17 19:49:16 CST; 2min 26s ago
Docs: man:firewalld(1)
Main PID: 13751 (firewalld)
CGroup: /system.slice/firewalld.service
└─13751 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
[root@ligen ~]# firewall-cmd --get-zones
block dmz drop external home internal public trusted work
如下命令可以查看系统默认zone:
[root@ligen ~]# firewall-cmd --get-default-zone
work
[root@ligen ~]# firewall-cmd --set-default-zone=public
[root@ligen ~]# firewall-cmd --get-zone-of-interface=ens33
public
[root@ligen ~]# firewall-cmd --set-default-zone=public
success
[root@ligen ~]# firewall-cmd --get-default-zone
public
[root@ligen ~]# firewall-cmd --get-zone-of-interface=ens33
public
[root@ligen ~]# firewall-cmd --zone=public --add-interface=lo
success
[root@ligen ~]# firewall-cmd --zone=work --change-interface=lo
success
[root@ligen ~]# firewall-cmd --zone=work --remove-interface=lo
success
[root@ligen ~]# firewall-cmd --get-active-zones
public
interfaces: ens33
[root@ligen ~]# ls /usr/lib/firewalld/services/
amanda-client.xml jenkins.xml puppetmaster.xml
amanda-k5-client.xml kadmin.xml quassel.xml
bacula-client.xml kerberos.xml radius.xml
bacula.xml kibana.xml redis.xml
bgp.xml klogin.xml RH-Satellite-6.xml
bitcoin-rpc.xml kpasswd.xml rpc-bind.xml
bitcoin-testnet-rpc.xml kprop.xml rsh.xml
bitcoin-testnet.xml kshell.xml rsyncd.xml
[root@ligen ~]# ls /etc/firewalld/services/
查看某个zone下面的service:
[root@ligen ~]# firewall-cmd --list-services
ssh dhcpv6-client
[root@ligen ~]# firewall-cmd --zone=public --list=service
usage: see firewall-cmd man page
firewall-cmd: error: ambiguous option: --list=service could match --list-lockdown-whitelist-contexts, --list-all, --list-lockdown-whitelist-uids, --list-ports, --list
一个zone下面有某个service,意味着这个service是被信任的。
[root@ligen ~]# firewall-cmd --zone=public --add-service=http
success
[root@ligen ~]# firewall-cmd --zone=public --list-service
ssh dhcpv6-client http
永久生效:
[root@ligen ~]# firewall-cmd --zone=public --add-service=http --permanent
例如:
ftp 端口1122 要在work zone上放行ftp:
[root@ligen ~]# cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services/ftp.xml
[root@ligen services]# vim ftp.xml 更改端口
[root@ligen firewalld]# cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/
[root@ligen firewalld]# cat zones/work.xml
Work
For use in work areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.
#增加了一行
重新加载:
[root@ligen firewalld]# firewall-cmd --reload
success
查看:
[root@ligen firewalld]# firewall-cmd --zone=work --list-service
ssh ftp dhcpv6-client
root@ecs-cebb ~]# crontab -e #创建
no crontab for root - using an empty one
crontab: installing new crontab
[root@ecs-cebb ~]# crontab -l #查看
1 10 1-10 */2 2,5 /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log
[root@ecs-cebb ~]# ps aux | grep cron #查看进程
root 2323 0.0 0.0 112708 976 pts/0 S+ 21:40 0:00 grep --color=auto cron
root 6536 0.0 0.0 126320 1660 ? Ss Apr02 0:01 /usr/sbin/crond -n
[root@ecs-cebb ~]# systemctl status crond
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-04-02 10:04:54 CST; 2 weeks 3 days ago
Main PID: 6536 (crond)
[root@ecs-cebb ~]# crontab -r #删除
linux系统所有的预设服务都可以通过查看/etc/init.d/
[root@ligen ~]# ls /etc/init.d
cloudResetPwdAgent denyhosts multi-queue-hw network
cloudResetPwdUpdateAgent functions netconsole README
系统的预设服务都可以通过service 服务名 start|stop|restart实现。这里的服务名就是/etc/init.d/,还可以用命令/etc/init.d/服务名实现。
[root@ligen ~]# chkconfig --list #也可以实现列出所有服务。
cloudResetPwdAgent 0:off 1:off 2:on 3:on 4:on 5:on 6:off
cloudResetPwdUpdateAgent 0:off 1:off 2:on 3:on 4:on 5:on 6:off
denyhosts 0:off 1:off 2:on 3:on 4:on 5:on 6:off
multi-queue-hw 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:off 3:off 4:off 5:off 6:off
运行级别:
0:关机
1:单用户模式
2:支持无nfs多用户模式
3:完全多用户模式
4:保留
5:图形登入方式
6:重启
[root@ligen ~]# chkconfig --level 2 network on
[root@ligen ~]# chkconfig --level 345 network off
[root@ligen ~]# chkconfig network off
增加系统服务:
[root@ligen ~]# cp /etc/init.d/network /etc/init.d/123
[root@ligen ~]# chkconfig --add 123
[root@ligen ~]# chkconfig --list |grep 123
123 0:off 1:off 2:on 3:on 4:on 5:on 6:off
删除:
[root@ligen ~]# chkconfig --del 123
system支持多个服务并发启动,而sysv只能一个一个地启动。
列出系统所有服务:
[root@ligen ~]# systemctl list-units --all --type=service
对应的服务器的脚本路径:/usr/lib/systemd/system/
[root@ligen ~]# ls /usr/lib/systemd/system
system/ systemd-journald systemd-sleep
systemd systemd-localed systemd-socket-proxyd
systemd-ac-power systemd-logind systemd-sysctl
systemd-activate systemd-machined systemd-sysv-install
systemd-backlight systemd-machine-id-commit systemd-timedated
systemd-binfmt systemd-modules-load systemd-udevd
systemd-bootchart systemd-pull systemd-update-done
unit分类:
service:系统服务。
target:多个unit组成的组
device:硬件设备
mount:文件系统挂载
automuont:自动挂载点
path:文件或路径
scope:不是有systemd启动的外部进程
slice:进程组
snapshot:systemd快照
socket:进程间套接字
swap:swap文件
timer:定时器
关于systemctl的常用命令:
[root@ligen ~]# systemctl restart crond
[root@ligen ~]# systemctl stop crond
[root@ligen ~]# systemctl status crond
[root@ligen ~]# systemctl start crond
[root@ligen ~]# systemctl is-enabled crond
enabled
关于unit的一些常用命令:
[root@ligen ~]# systemctl list-units
[root@ligen ~]# systemctl list-units -all
[root@ligen ~]# systemctl list-units -all --state=inactive
[root@ligen ~]# systemctl list-units --all --type=target
[root@ligen ~]# systemctl list-units --type=service
[root@ligen ~]# systemctl list-unit-files --type=target #查看系统所有的target
[root@ligen ~]# systemctl list-dependencies multi-user.target #查看某个target包含的unit
[root@ligen ~]# systemctl get-default #查看默认的target
multi-user.target
target、unit、service之间的关系:
target包含很多service
target由很多unit组成
一个service属于一种unit