LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 294|回复: 0

关闭网络服务

[复制链接]
发表于 2024-1-30 23:43:04 | 显示全部楼层 |阅读模式
当你第一次使用 systemctl 观察本地服务器启动的服务时,会发现有很多 daemon,这是因为 systemd 将许多原本不被列为 daemon 的程序也纳入管理检测范围内,但是那些大部分都属于 Linux 系统基础运行所需的环境,你不清楚的情况下,最好不要去修改他们

除了本地服务之外,要观察网络服务,虽然网络服务默认有 SELinux 管理,不过,还是建议非必要的网络服务就关闭它。基本上会产生一个网络监听端口的程序,就可以称它为网络服务了,可通过如下方式观察网络端口

[root@study ~]# netstat -tlunp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1578/master         
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      2350/sshd: mrcode@p
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN      10579/sshd: root@pt
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1975/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1378/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1578/master         
tcp6       0      0 ::1:6010                :::*                    LISTEN      2350/sshd: mrcode@p
tcp6       0      0 ::1:6011                :::*                    LISTEN      10579/sshd: root@pt
tcp6       0      0 :::555                  :::*                    LISTEN      11573/vsftpd        
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::22                   :::*                    LISTEN      1378/sshd           
udp        0      0 192.168.122.1:53        0.0.0.0:*                           1975/dnsmasq        
udp        0      0 0.0.0.0:67              0.0.0.0:*                           1975/dnsmasq        
udp        0      0 0.0.0.0:111             0.0.0.0:*                           1/systemd           
udp        0      0 0.0.0.0:33017           0.0.0.0:*                           920/avahi-daemon: r
udp        0      0 0.0.0.0:669             0.0.0.0:*                           925/rpcbind         
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           920/avahi-daemon: r
udp6       0      0 :::111                  :::*                                1/systemd           
udp6       0      0 :::669                  :::*                                925/rpcbind


比如上面显示 avahi-daemon 服务监听了 5353 和 33017 端口,可以通过 systemctl 查找是否真的有 avahi-daemon 服务

[root@study ~]# systemctl list-units --all | grep avahi-daemon
  avahi-daemon.service                                                                                           loaded    active   running   Avahi mDNS/DNS-SD Stack
  avahi-daemon.socket                                                                                            loaded    active   running   Avahi mDNS/DNS-SD Stack Activation Socket


avahi-daemon 的目的是在局域网进行类似网芳的搜索,因此这个服务可以协助你在区网内随时了解即插即用的设备。包括笔记本电脑等,只要你连上区网,你就能知道谁进来了。问题是,你可能不需要这个协议,关闭它

# 关闭两个服务,并且取消开机启动
[root@study ~]# systemctl stop avahi-daemon.service
Warning: Stopping avahi-daemon.service, but it can still be activated by:
  avahi-daemon.socket
[root@study ~]# systemctl stop avahi-daemon.socket  
[root@study ~]# systemctl disable avahi-daemon.service avahi-daemon.socket
Removed symlink /etc/systemd/system/multi-user.target.wants/avahi-daemon.service.
Removed symlink /etc/systemd/system/sockets.target.wants/avahi-daemon.socket.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.Avahi.service.
[root@study ~]# netstat -tlunp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1578/master         
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      2350/sshd: mrcode@p
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN      10579/sshd: root@pt
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1975/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1378/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1578/master         
tcp6       0      0 ::1:6010                :::*                    LISTEN      2350/sshd: mrcode@p
tcp6       0      0 ::1:6011                :::*                    LISTEN      10579/sshd: root@pt
tcp6       0      0 :::555                  :::*                    LISTEN      11573/vsftpd        
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::22                   :::*                    LISTEN      1378/sshd           
udp        0      0 192.168.122.1:53        0.0.0.0:*                           1975/dnsmasq        
udp        0      0 0.0.0.0:67              0.0.0.0:*                           1975/dnsmasq        
udp        0      0 0.0.0.0:111             0.0.0.0:*                           1/systemd           
udp        0      0 0.0.0.0:669             0.0.0.0:*                           925/rpcbind         
udp6       0      0 :::111                  :::*                                1/systemd           
udp6       0      0 :::669                  :::*                                925/rpcbind  


一般来说,你本地服务器至少需要 25 端口,而 22 端口最好加上防火墙来管理远程联机登录比较妥当。555 端口是我们前面练习测试修改的。这样的系统能够被黑的机会已经少很多了。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表