418 字
2 分钟
Linux各端口的关闭

有句话叫什么…

开放的端口,是被入侵的开始#

这3种网络管理守护进程是Linux系统下常用的进程间互斥同步#

假如一个设备没有开放的逻辑端口,并且没有连接网络 那除了物理黑似乎也没别的办法

今天我们就来搞一下端口的那些事#

首先,确保安装 net-tools 工具#

根据自己的系统环境选择代码执行

Terminal window
sudo apt update && sudo apt install net-tools # Ubuntu/Debian
sudo pacman -Syy && sudo pacman -S net-tools # Manjaro/Archlinux
sudo yum install net-tools # CentOS/RHEL
sudo pkg install net-tools # 你懂的

  • 关闭远程连接SSH端口(22)
Terminal window
sudo systemctl status sshd.service # 查看运行情况
sudo systemctl stop sshd.service # 显示运行中则关闭
sudo systemctl disable sshd.service # 禁用开机自启动
  • 禁用邮件传输代理Postfix端口(25)
Terminal window
sudo systemctl status postfix.service # 查看运行情况
sudo systemctl stop postfix.service # 关闭端口
sudo systemctl disable postfix.service # 禁用开机自启动
  • 禁用网络打印机Cups端口(631)
Terminal window
sudo systemctl status cups.service # 查看运行情况
sudo systemctl stop cups.service # 关闭端口
sudo systemctl disable cups.service # 禁用开机自启动
  • 禁用本地域名解析DNS端口(5355和127.0.0.53/54:53)
Terminal window
# 修改配置文件
vim /etc/systemd/resolved.conf
# 编辑或修改以下配置信息
LLMNR=0
DNSStubListener=no
# 保存后查看相关服务运行情况并禁用与关闭开机自启动
sudo systemctl status avahi-deamon.socket
sudo systemctl stop avahi-deamon.socket
sudo systemctl disable avahi-deamon.socket
# 重启内核域名服务以加载配置文件(可选项)
sudo systemctl restart systemd-resolved.service
# 建立软连接
ln -sf /run/systemd/resolve/resolved.conf /etc/resolved.conf
# 重启系统生效
reboot
# 重启后查看端口占用情况
netstat -anp | grep 5353
netstat -nltp
Linux各端口的关闭
https://cyber-mobile.net/posts/linux各端口的关闭/
作者
dot1q
发布于
2024-06-23
许可协议
CC BY-NC-SA 4.0