Linux系统端口关闭并排查相关自启动项(麒麟环境)

0.获取前置信息

确认占用端口服务

bash 复制代码
1)提权到root用户
sudo -s
2)查找端口对应服务和进程号
netstat -tunlp | grep 'port'
lsof -i :port

1.systemd自启动项关闭

常规服务关闭

bash 复制代码
0)查看所有systemd自启动服务
systemctl list-unit-files --state=enabled
1)关闭服务自启动
systemctl disable 'service_name' --now
2)关闭对应进程
kill -9 PID
3)查看对应服务状态
systemctl status service_name

防火墙封禁端口(可选)

bash 复制代码
1)封禁端口,并重载
firewell-cmd --permanent --remove-port='port'/tcp
firewell-cme --reload
2)查看端口是否被封禁
firewell-cme --query-port='port'/tcp

2.rc.local脚本自启动排查

bash 复制代码
1)检查rc.local是否存在并启用
ls -l /etc/rc*
2)注释相关服务,停止自启动
vim /etc/rc.loacl
3)禁止rc.local自启
systemctl disable rc-local --now

3.桌面自启动autostart程序关停(麒麟专属)

bash 复制代码
1)查看autostart自启动程序
ls -l /etc/xdg/autostart/
2)关闭自启动项
rm -rf /etc/xdg/autostart/'进程名'.desktop

4.cron定时任务排查

bash 复制代码
1)查看当前用户cron任务
crontab -l
2)查看系统级cron任务
cat /etc/crontab
ls -l /etc/cron.d
3)编辑相关任务
crontab -e

5.传统SysV init脚本排查(兼容模式)

bash 复制代码
1)查看所有服务
service --status-all
2)查看某服务是否自启
chkconfig --list 服务名
3)禁止服务自启
chkconfig 服务名 off

6.日志排查(异常自启)

bash 复制代码
查看系统启动日志
journalctl -b
查看某服务日志
journalctl -u 服务名
相关推荐
zzzzzz3102 天前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql
XIAOHEZIcode2 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
用户0328472220702 天前
如何搭建本地yum源(上)
运维
A小辣椒4 天前
TShark:Wireshark CLI 功能
linux
A小辣椒4 天前
TShark:基础知识
linux
AlfredZhao4 天前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao4 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334665 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪5 天前
linux 拷贝文件或目录到指定的位置
linux
大树885 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai