zoukankan      html  css  js  c++  java
  • CentOS关闭系统不必要的端口

    注:以下所有操作均在CentOS 7.2 x86_64位系统下完成。

    1)首先查看当前系统开放的端口号:

    # netstat -tlnup
    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:9000          0.0.0.0:*               LISTEN      30389/php-fpm: mast
    tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      30425/nginx: master
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2151/sshd           

    可以看到目前系统监听的端口有四个,分别是:

    • 9000端口:php-fpm使用中;
    • 111端口:系统使用中;
    • 80端口:Nginx使用中;
    • 22端口:sshd服务使用中;

    我们决定关闭111端口。

    2)查看111端口正在被哪个服务在使用中:

    # 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端口的服务的详细状态信息:

    # systemctl list-unit-files --all |grep portmapper
    # systemctl list-unit-files --all |grep rpcbind
    rpcbind.service                               enabled
    rpcbind.socket                                enabled
    rpcbind.target                                static

    可以看到这两个服务名称分别是rpcbind.service和rpcbind.socket,并且设置了自启动。

    4)接下来我们关闭这两个服务:

    # systemctl stop rpcbind.service
    Warning: Stopping rpcbind.service, but it can still be activated by:
      rpcbind.socket
    # systemctl stop rpcbind.socket

    这个时候可以再查看下系统开放端口信息:

    # netstat -tlnup
    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:9000          0.0.0.0:*               LISTEN      30389/php-fpm: mast
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      30425/nginx: master
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2151/sshd    

    可以看到111端口已经没有被使用。

    5)由于前面看到这两个服务都被设置了开机自启动,所以还要将其设置为开机不自启动:

    # systemctl disable rpcbind.service
    Removed symlink /etc/systemd/system/multi-user.target.wants/rpcbind.service.
    # systemctl disable rpcbind.socket
    Removed symlink /etc/systemd/system/sockets.target.wants/rpcbind.socket.

    这个时候再来查看下服务的详细状态信息:

    # systemctl list-unit-files --all |grep rpcbind
    rpcbind.service                               disabled
    rpcbind.socket                                disabled
    rpcbind.target                                static

    这两个服务的自启动项已经被设置为禁用。

    至此,本次工作完成。

  • 相关阅读:
    Django测试开发-36- xadmin模板中缩略图django-stdimage
    Django测试开发-35- xadmin模板中添加上传文件和图片功能
    Django测试开发-34- xadmin模板中添加action插件
    Django测试开发-33- xadmin模板中添加小组件报错
    Django测试开发-32- xadmin模板使用自定义菜单项
    Django测试开发-31- xadmin模板中choices使用
    序列化模块
    一大群模块
    python基础之内置函数和匿名函数
    python基础之迭代器和生成器
  • 原文地址:https://www.cnblogs.com/brishenzhou/p/11770206.html
Copyright © 2011-2022 走看看