본문 바로가기
IT/linux

포트 보안을 위한 서비스 중지 목록 및 방법

by 어느해겨울 2021. 12. 28.

포트 보안을 위한 서비스 중지 목록 및 방법

 

포트 보안을 위한 서비스 제어의 목적은 외부로 노출된 포트와 잘 알려진 포트들의 서비스를 중지 또는 포트의
변경을 목적으로 한다. 

아래의 몇 가지 검사/정지 패턴을 상황에 맞게 사용하면 된다.

 

 

1. rpcbind, 서비스 중지
 * 상태 확인, 1인 경우 활성 및 동작 중
  - systemctl status rpcbind | grep Active | grep running | wc -l

 * 중지 및 비활성화
  - systemctl stop rpcbind
  - systemctl disable rpcbind

 * 활성 및 시작
  - systemctl enable rpcbind
  - systemctl start rpcbind


2. mosquitto, 서비스 중지
 * 상태 확인, 1인 경우 활성 및 동작 중
  - systemctl status mosquitto | grep Active | grep running | wc -l

 * 중지 및 비활성화
  - systemctl stop mosquitto
  - systemctl disable mosquitto

 * 활성 및 시작
  - systemctl enable mosquitto
  - systemctl start mosquitto


3. sshd, IPv6 비활성화
 * 상태 확인, 1인 경우 IPv6 활성 상태
  - cat /etc/ssh/sshd_config | grep AddressFamily | wc -l
 
 * IPv6 비활성
  - echo "AddressFamily inet # IPv4 only" >> /etc/ssh/sshd_config
  - service ssh restart

 * IPv6 활성
  - sed -i '/AddressFamily/d' /etc/ssh/sshd_config
  - service ssh restart

 * 상태 확인, 1인 경우 활성 및 동작 중
  - systemctl status ssh | grep Active | grep running | wc -l

 * 중지 및 비활성화
  - systemctl stop ssh
  - systemctl disable ssh

 * 활성 및 시작
  - systemctl enable ssh
  - systemctl start ssh


4. mysqld, IPv6 비활성화 및 외부 접근 서비스 중지
 * 상태 확인, 1인 경우 IPv6 활성 상태
  - cat /etc/mysql/my.cnf 2> /dev/null | grep bind-address | grep \# | wc -l

 * IPv6 비활성화 및 local bind
  - sed -i 's/^#bind-address/bind-address/g' /etc/mysql/my.cnf
  - service mysql restart

 * IPv6 활성화 및 local bind 해제
  - sed -i 's/^bind-address/#bind-address/g' /etc/mysql/my.cnf
  - service mysql restart


5. apache, 외부 접근 서비스 중지
 * 상태 확인, 0인 경우 외부 접근 가능
  - cat /etc/apache2/ports.conf | grep 127.0.0.1 | wc -l

 * local bind
  - sed -i 's/8100/127.0.0.1:8100/g' /etc/apache2/ports.conf
  - service apache2 restart

 * local bind 해제
  - sed -i 's/127.0.0.1:8100/8100/g' /etc/apache2/ports.conf
  - service apache2 restart

 

6. haproxy, 포트 변경
 * 지정된 포트로 변경 (ex. 80)
  - sed -i 's/^frontend.*/frontend all *:80/g' /opt/interm/conf/haproxy.cfg
  - ps -ef | grep haproxy | grep -v monitor | grep -v grep | awk {'print $2'} | xargs kill

 

 

댓글