關閉Linux無用端口


關閉系統不必要的端口,增強系統安全,此處以關閉111端口為例進行說明。

1)、查看本機正在監聽的端口:

[root@b ~]# netstat -tlnup 

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
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 7372/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6929/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 6934/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7243/master
tcp6 0 0 :::3306 :::* LISTEN 7189/mysqld
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 6929/sshd
tcp6 0 0 ::1:631 :::* LISTEN 6934/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 7243/master
udp 0 0 192.168.122.1:53 0.0.0.0:* 7372/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 7372/dnsmasq
udp 0 0 0.0.0.0:68 0.0.0.0:* 6729/dhclient
udp 0 0 0.0.0.0:111 0.0.0.0:* 1/systemd
udp 0 0 0.0.0.0:5353 0.0.0.0:* 6246/avahi-daemon:
udp 0 0 127.0.0.1:323 0.0.0.0:* 6267/chronyd
udp 0 0 0.0.0.0:45917 0.0.0.0:* 6246/avahi-daemon:
udp6 0 0 :::111 :::* 1/systemd
udp6 0 0 ::1:323 :::* 6267/chronyd

2)、查看正在監聽的111端口,由哪個服務使用

[root@b ~]# cat /etc/services | grep -w 111
sunrpc 111/tcp portmapper rpcbind # RPC 4.0 portmapper TCP
sunrpc 111/udp portmapper rpcbind # RPC 4.0 portmapper UDP

3)、查看使用111端口服務的詳細狀態信息

[root@b ~]# systemctl list-unit-files --all |grep portmapper
[root@b ~]# systemctl list-unit-files --all |grep rpcbind
rpcbind.service disabled
rpcbind.socket enabled
rpcbind.target static

4)、關閉正在使用111端口的服務,並設置開機不啟動該服務
[root@b ~]# systemctl stop rpcbind.socket
[root@b ~]# systemctl disable rpcbind.socket
Removed symlink /etc/systemd/system/sockets.target.wants/rpcbind.socket.

 

實際操作截屏

 

關閉其他端口

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM