服务命令比较
操作 | Linux 6 | Linux7 |
服务开机自动启动 | chkconfig --level 35 iptables on | systemctl enable firewalld.service |
服务器开机不自动启动 | chkconfig --level 35 iptables off | systemctl disable firewalld.service |
加入自定义服务 | chkconfig --add aaa | systemctl load aaa.service |
删除服务 | chkconfig --del aaa | 停止服务,删除相应的配置文件 |
显示所有已经启动的服务 | chkconfig -- list | systemctl list-unis --type=service |
启动服务 | service iptables start | systemctl start firewalld.service |
停止服务 | service iptables stop | systemctl stop firewalld.service |
服务状态 | service iptables status | systemctl status firewalld.service |
重启服务 | service iptables restart | systemctl restart firewalld.service |
Linux 6
[root@mysql57 ~]# service iptables status
iptables: Firewall is not running.
[root@mysql57 ~]# service iptables start
iptables: Applying firewall rules: [ OK ]
[root@mysql57 ~]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
[root@mysql57 ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@mysql57 ~]# service iptables status
iptables: Firewall is not running.
[root@mysql57 ~]# chkconfig --list | more
NetworkManager 0:off 1:off 2:off 3:off 4:off 5:off 6:off
abrt-ccpp 0:off 1:off 2:off 3:on 4:off 5:on 6:off
abrtd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
acpid 0:off 1:off 2:on 3:on 4:on 5:on 6:off
atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
autofs 0:off 1:off 2:off 3:on 4:on 5:on 6:off
blk-availability 0:off 1:on 2:on 3:on 4:on 5:on 6:off
bluetooth 0:off 1:off 2:off 3:on 4:on 5:on 6:off
certmonger 0:off 1:off 2:off 3:on 4:on 5:on 6:off
cpuspeed 0:off 1:on 2:on 3:on 4:on 5:on 6:off
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
cups 0:off 1:off 2:on 3:on 4:on 5:on 6:off
dnsmasq 0:off 1:off 2:off 3:off 4:off 5:off 6:off
firstboot 0:off 1:off 2:off 3:off 4:off 5:off 6:off
haldaemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off
htcacheclean 0:off 1:off 2:off 3:off 4:off 5:off 6:off
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
ip6tables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
irqbalance 0:off 1:off 2:off 3:on 4:on 5:on 6:off
kdump 0:off 1:off 2:off 3:off 4:off 5:off 6:off
lvm2-monitor 0:off 1:on 2:on 3:on 4:on 5:on 6:off
mdmonitor 0:off 1:off 2:on 3:on 4:on 5:on 6:off
messagebus 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
netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off
nfslock 0:off 1:off 2:off 3:on 4:on 5:on 6:off
ntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off
oddjobd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
portreserve 0:off 1:off 2:on 3:on 4:on 5:on 6:off
postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
psacct 0:off 1:off 2:off 3:off 4:off 5:off 6:off
quota_nld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
35启动级别关闭自启动
[root@mysql57 ~]# chkconfig --level 35 iptables off
[root@mysql57 ~]# ls /etc/init.d/
abrt-ccpp cups irqbalance nfslock rngd spice-vdagentd
abrtd dnsmasq kdump ntpd rpcbind sshd
abrt-oops firstboot killall ntpdate rpcgssd sssd
acpid functions lvm2-lvmetad oddjobd rpcidmapd sysstat
atd haldaemon lvm2-monitor ohasd rpcsvcgssd udev-post
auditd halt mdmonitor portreserve rsyslog wdaemon
autofs htcacheclean messagebus postfix sandbox winbind
blk-availability httpd netconsole psacct saslauthd wpa_supplicant
bluetooth init.ohasd netfs quota_nld single ypbind
certmonger init.tfa network rdisc smartd
cpuspeed ip6tables NetworkManager restorecond snmpd
crond iptables nfs rhnsd snmptrapd
Linux 7
[root@mysql57 ~]# cd /etc/systemd/system/
basic.target.wants/
bluetooth.target.wants/
default.target.wants/
dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants/
getty.target.wants/
graphical.target.wants/
local-fs.target.wants/
multi-user.target.wants/
network-online.target.wants/
printer.target.wants/
remote-fs.target.wants/
sockets.target.wants/
sysinit.target.wants/
systemd-remount-fs.service.wants/
system-update.target.wants/
timers.target.wants/
vmtoolsd.service.requires/
[root@mysql57 ~]# cd /etc/systemd/system/
[root@mysql57 system]# ls
basic.target.wants
bluetooth.target.wants
dbus-org.bluez.service
dbus-org.fedoraproject.FirewallD1.service
dbus-org.freedesktop.Avahi.service
dbus-org.freedesktop.ModemManager1.service
dbus-org.freedesktop.nm-dispatcher.service
default.target
default.target.wants
dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants
display-manager.service
getty.target.wants
graphical.target.wants
local-fs.target.wants
multi-user.target.wants
network-online.target.wants
printer.target.wants
remote-fs.target.wants
sockets.target.wants
sysinit.target.wants
systemd-remount-fs.service.wants
system-update.target.wants
timers.target.wants
vmtoolsd.service.requires
[root@mysql57 system]# cd multi-user.target.wants/
[root@mysql57 multi-user.target.wants]# ls
abrt-ccpp.service initial-setup-reconfiguration.service remote-fs.target
abrtd.service irqbalance.service rhel-configure.service
abrt-oops.service ksm.service rngd.service
abrt-vmcore.service ksmtuned.service rpcbind.service
abrt-xorg.service libstoragemgmt.service rsyslog.service
atd.service libvirtd.service smartd.service
auditd.service mcelog.service sshd.service
avahi-daemon.service mdmonitor.service sysstat.service
brandbot.path ModemManager.service tuned.service
crond.service NetworkManager.service vdo.service
cups.path nfs-client.target vmtoolsd.service
cups.service oracleasm.service
firewalld.service postfix.service
[root@mysql57 multi-user.target.wants]# cd ..
[root@mysql57 system]# find ./ -name fire*
./multi-user.target.wants/firewalld.service
[root@mysql57 system]# cd multi-user.target.wants/
[root@mysql57 multi-user.target.wants]# cd /usr/lib/systemd/
[root@mysql57 systemd]# ls
catalog systemd-coredump systemd-shutdown
import-pubring.gpg systemd-cryptsetup systemd-shutdownd
ntp-units.d systemd-fsck systemd-sleep
ol-consolebaud systemd-hibernate-resume systemd-socket-proxyd
rhel-autorelabel systemd-hostnamed systemd-sysctl
rhel-configure systemd-importd systemd-sysv-install
rhel-dmesg systemd-initctl systemd-timedated
rhel-dmraid-activation systemd-journald systemd-udevd
rhel-domainname systemd-localed systemd-update-done
rhel-import-state systemd-logind systemd-update-utmp
rhel-loadmodules systemd-machined systemd-user-sessions
rhel-readonly systemd-machine-id-commit systemd-vconsole-setup
scripts systemd-modules-load system-generators
system systemd-pstore system-preset
systemd systemd-pull system-shutdown
systemd-ac-power systemd-quotacheck system-sleep
systemd-activate systemd-random-seed user
systemd-backlight systemd-readahead user-generators
systemd-binfmt systemd-remount-fs user-preset
systemd-bootchart systemd-reply-password
systemd-cgroups-agent systemd-rfkill
[root@mysql57 systemd]# systemctl status firewalld.service
实际加载的/usr/lib/systemd/system/firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-08-23 13:05:37 CST; 12min ago
Docs: man:firewalld(1)
Main PID: 1026 (firewalld)
Tasks: 2
CGroup: /system.slice/firewalld.service
└─1026 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
Aug 23 13:05:36 mysql57.example.com systemd[1]: Starting firewalld - dynamic firewal.....
Aug 23 13:05:37 mysql57.example.com systemd[1]: Started firewalld - dynamic firewall...n.
Aug 23 13:05:37 mysql57.example.com firewalld[1026]: WARNING: AllowZoneDrifting is en....
Hint: Some lines were ellipsized, use -l to show in full.
[root@mysql57 system]# ls | grep firewalld
firewalld.service
[root@mysql57 system]# pwd
/usr/lib/systemd/system
关闭防火墙
[root@mysql57 system]# systemctl stop firewalld.service
disable
[root@mysql57 system]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
启动防护墙,开机不启动因为是disabled
[root@mysql57 system]# systemctl start firewalld.service
[root@mysql57 system]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2022-08-23 15:14:24 CST; 2s ago
Docs: man:firewalld(1)
Main PID: 4701 (firewalld)
Tasks: 4
CGroup: /system.slice/firewalld.service
├─4701 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
├─4729 /usr/sbin/modprobe nf_conntrack
├─4730 sh -c /usr/sbin/modprobe --ignore-install nf_conntrack && /usr/sb...
└─4731 /usr/sbin/modprobe --ignore-install nf_conntrack
Aug 23 15:14:19 mysql57.example.com systemd[1]: Starting firewalld - dynamic firewal.....
Aug 23 15:14:24 mysql57.example.com systemd[1]: Started firewalld - dynamic firewall...n.
Aug 23 15:14:25 mysql57.example.com firewalld[4701]: WARNING: AllowZoneDrifting is en....
Hint: Some lines were ellipsized, use -l to show in full.