InfraPlatform

Linux - firewall-cmd 서비스 명칭 기반 관리

IT오이시이 2025. 10. 15. 01:01
728x90

- (꿀팁) 리눅스 방화벽 설정 - ufw firewall-cmd

- How to add Firewall rules on Redhat 9 - Allow MySQL Service Through the Firewall

 

Linux - firewall-cmd 서비스 명칭 기반 관리

firewalld에서는 포트 번호 대신 서비스 명칭으로 방화벽을 관리하는 것이 가능합니다

1. 기본 내장 서비스 사용 방법

  • 지원되는 서비스 목록 조회:
  • firewall-cmd --get-services
  • zone에 서비스 오픈(예: HTTP, HTTPS):
  • sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
  • 현재 적용된 서비스 확인:
  • firewall-cmd --list-services --zone=public

firewall-cmd --get-services

#zone에 서비스 오픈(예: HTTP, HTTPS):
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

# 현재 적용된 서비스 확인:
firewall-cmd --list-services --zone=public

2. 커스텀 서비스 정의 방법

  1. /etc/firewalld/services/에 XML 파일 생성(예: myapp.xml):
  2. <service> <short>myapp</short> <description>Custom App on 7000, 15433</description> <port protocol="tcp" port="7000"/> <port protocol="tcp" port="15433"/> </service>
  3. 파일 등록 후 서비스 등록:
  4. sudo firewall-cmd --permanent --add-service=myapp sudo firewall-cmd --reload

 

[/etc/firewalld/services/service-myapp.xml]

<service> 
  <short>myapp</short> 
  <description>Custom App on 7000, 15433</description>
  <port protocol="tcp" port="7000"/>
  <port protocol="tcp" port="15433"/>
 </service>

firewall-cmd --new-service-from-file=service-myapp.xml
# or 
sudo firewall-cmd --permanent --add-service=service-myapp
sudo firewall-cmd --reload

# 파일을 복사하여 적용가능
cp /usr/lib/firewalld/services/service-name.xml /etc/firewalld/services/service-name.xml

 

이런 방식은 포트 기반이 아니라, 서비스 명칭 기반으로 여러 포트와 규칙을 한 번에 관리할 수 있어 시스템 운영이 효율적입니다.

 

[1] [redhat.com, (https://docs.redhat.com/ko/documentation/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/predefined-firewalld-services_using-and-configuring-firewalld)
[2]rockylinux.org (https://docs.rockylinux.org/10/ko/guides/security/firewalld-beginners/)
[3]리눅스 방화벽 설정, (https://couplewith.tistory.com/683)
[4]redhat.com,(https://docs.redhat.com/ko/documentation/red_hat_enterprise_linux/7/html/security_guide/sec-adding_new_services)
 [5]Server-firewall-cmd-service (https://velog.io/@inyong_pang/Server-firewall-cmd-service)

728x90
반응형