5.2. 명령줄 도우미를 사용하여 SELinux 문제 해결


다음 예제에서는 명령줄 도우미를 사용하여 SELinux 문제를 해결하는 단계를 제공합니다.

사전 요구 사항

  • 명령줄 도우미를 활성화했습니다.
  • 시스템에 대한 root 액세스 권한이 있습니다.

프로세스

  1. 터미널에서 다음 명령을 입력하여 시스템에 설치된 httpd 패키지 버전을 나열합니다.

    $ sudo rpm -qa httpd
    httpd-2.4.62-2.fc40.x86_64
  2. httpd.conf 파일 내용을 표시합니다.

    $ sudo cat /etc/httpd/conf/httpd.conf
    # This is the main Apache HTTP server configuration file.  It contains the
    # configuration directives that give the server its instructions.
    # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
    # In particular, see<URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
    # for a discussion of each configuration directive.
  3. 모든 httpdq 패키지를 쿼리합니다.

    $ sudo rpm -qa httpdq
  4. 웹 서버가 들어오는 요청을 수락하는 포트를 식별합니다.

    $ cat /etc/httpd/conf/httpd.conf | grep Listen
    # Listen: Allows you to bind Apache to specific IP addresses and/or
    # Change this to Listen on a specific IP address, but note that if
    #Listen 12.34.56.78:80
    Listen 80
  5. httpd 서비스를 다시 시작합니다.

    $ systemctl restart httpd
    
    Job for httpd. Service failed because the control process exited with error code.
    See “systemctl status httpd.service" and “journalctl -xeu httpd.service" for details.
    1. 실패한 서비스에 대한 자세한 내용은 journalctl 명령을 실행합니다.

      $ sudo journalctl -xeu httpd.service
  6. 명령줄 도우미를 사용하여 문제를 해결하고 서비스가 실패하는 이유를 확인합니다.

    $ sudo c “why did httpd fail to start"

    도우미의 제안 사항 중 하나는 ausearch 툴을 사용하여 감사 로그를 쿼리하고 메시지 유형 매개 변수에 AVCUSER_AVC 값을 사용하는 것입니다. 이를 위해 다음 명령을 실행합니다.

    $ sudo ausearch -m AVC,USER_AVC -ts recent
    1. selinux httpd 포트에 대한 명령행 도우미에게 문의하십시오.

      $ c “selinux httpd port"

      길잡이는 다음 명령으로 sestatus 명령을 사용하여 현재 SELinux 상태 및 httpd 서비스의 콘텐츠를 확인하는 것이 좋습니다.

      $ sudo sestatus
      
      SELinux status:                 enabled
      SELinuxfs mount:                /sys/fs/selinux
      SELinux root directory:         /etc/selinux
      Loaded policy name:             targeted
      Current mode:                   enforcing
      Mode from config file:          enforcing
      Policy MLS status:              enabled
      Policy deny_unknown status:     allowed
      Memory protection checking:     actual (secure)
      Max kernel policy version:      33
    2. 다음 명령을 실행하여 httpd 서비스에 대한 특정 SELinux 정책을 확인합니다.

      $ sudo cat /usr/share/selinux/targeted/contexts/httpd_var_run_t
      No such file or directory
    3. 컨텍스트에 대해 명령줄 도우미에 문의하십시오.

      $ c “i don't have a httpd_var_run_t contexts"

      명령줄 도우미는 요청을 처리하는 데 약간의 시간이 소요되고 가능한 몇 가지 제안을 제공합니다.

    4. 길잡이는 컨텍스트가 없을 수 있으며 다음 명령을 사용하여 설정할 필요가 있다고 합니다.

      $ sudo chcon -R -t httpd_var_run_t
    5. 포트에 대해 CLA에게 문의하십시오.

      $ c “selinux won't let httpd listen on port 12345"
    6. 다음 제안을 시도하고 명령을 실행합니다.

      $ sudo semage port -a -t httpd_port_t -p tcp 12345
      ValueError: Type httpd_port_t is invalid, must be a port type
    7. 출력에 표시되는 오류에 대해 CLA에 문의하십시오.

      $ c “how do I fix ValueError: Type httpd_port_t is invalid, must be a port type"
  7. CLA에서 제공하는 단계를 실행합니다.

    $  sudo getenforce
    Enforcing
    $ setenforce 0
    $ sudo systemctl restart httpd
    $ sudo systemctl status httpd
    
    $ sudo ls -Z /usr/sbin/httpd
    system_u:object_r:httpd_exec_t:s0 /usr/sbin/httpd
    
    $ chcon -t httpd_exec_t /usr/sbin/httpd
    
    $ sudo setenforce 1
    1. httpd 서비스를 다시 시작하고 httpd.service 의 상태를 확인합니다.

      $ sudo systemctl restart httpd
      Job failed
      
      $ sudo systemctl status httpd.service
      Failed to start the Apache Server
  8. CLA에 httpd 가 12345 포트에서 수신 대기하도록 설정하는 방법을 질문하십시오.

    $ c “how do I enable httpd to listen on port 12345 selinux"
    1. CLA에서 권고한 명령을 실행합니다.

      $ sudo setsebool -P httpd_can_network_connect=1
  9. httpd 서비스를 다시 시작하고 httpd.service 의 상태를 다시 확인합니다.

    $ sudo systemctl status htppd
    $ sudo systemctl restart httpd
    Job failed, see journalctl
  10. journalctl 서비스를 확인합니다.

    $ journalctl -xeu httpd
    Output: An ExecStart= process belonging to unit httpd.service has exited.
  11. 출력을 사용하여 CLA에 문제를 해결하도록 요청합니다.

    $ c “An ExecStart= process belonging to unit httpd.service has exited."
    1. CLA가 응답하는 명령을 실행합니다.

      $ sudo ausearch -m AVC,USER_AVC -ts recent
      Output: “avc:  denied  {name_bind}  for pid=7184 comm="httpd” src=12345 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r: unreserved_port_t:s0 tclas=tcp_socket permissive=0"
    2. 이전 명령의 출력을 복사합니다.

      $ sudo c ““avc: denied {name_bind} for pid=7184 comm="httpd” src=12345 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r: unreserved_port_t:s0 tclas=tcp_socket permissive=0”
    3. 다음 명령을 실행하여 "SELinux가 Apache Server(httpd)로 인해 포트 12345에 바인딩되지 않음 오류를 해결합니다.

      $ sudo semage port -a -t http_port_t -p tcp 12345
  12. httpd 서비스를 다시 시작하고 httpd.service 의 상태를 확인합니다.

    $ sudo systemctl restart httpd
    No error
    $ sudo systemctl status httpd.service

    서버가 구성 및 실행 중이고 포트 443,12345 에서 수신 대기 중입니다.

Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 문서 정보

Legal Notice

Theme

© 2026 Red Hat
맨 위로 이동