[Linux/방화벽] Linux 서버에서 iptables 제거 후 firewalld로 전환하기

2026. 5. 21. 19:48카테고리 없음

Linux 서버에서 iptables 제거 후 firewalld로 전환하기

 

운영 중인 Linux 서버에서 기존 iptables 설정을 제거하고 firewalld 기반으로 정리하는 방법을 정리한다.

특히 아래와 같은 상황에서 유용하다.

  • 예전에 등록된 iptables rule이 계속 살아나는 경우
  • firewall-cmd 사용 중인데 iptables 체인이 계속 보이는 경우
  • firewalld 기준으로 방화벽 정책을 일원화하고 싶은 경우

1. iptables 종료 및 저장된 룰 완전 삭제

1-1. iptables 서비스 확인

systemctl status iptables

만약 아래와 같이 나온다면 iptables 서비스는 현재 비활성 상태이다.

Unit iptables.service could not be found.

1-2. 저장된 iptables 룰 백업 및 제거

대부분 RHEL / CentOS 계열에서는 아래 경로에 저장된다.

/etc/sysconfig/iptables

백업:

cp /etc/sysconfig/iptables /etc/sysconfig/iptables.bak

제거:

mv /etc/sysconfig/iptables /etc/sysconfig/iptables.bak.old

 

제거 할 거라면 mv만 해도 무방(백업 및 제거의 효과)


1-3. 현재 메모리에 적용된 iptables 룰 제거

iptables -F
iptables -X

iptables -t nat -F
iptables -t nat -X

iptables -t mangle -F
iptables -t mangle -X

정책 초기화:

iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

 

정책 제거 확인:

iptables -L -n

 정책란이 공란이면 됨.


2. firewalld 기동 및 룰 등록

2-1. firewalld 활성화

systemctl enable firewalld
systemctl start firewalld

상태 확인:

systemctl status firewalld

2-2. 자주 사용하는 포트 등록

WEB

firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp

SSH

firewall-cmd --permanent --add-port=22/tcp

Mail

firewall-cmd --permanent --add-port=25/tcp
firewall-cmd --permanent --add-port=465/tcp
firewall-cmd --permanent --add-port=110/tcp
firewall-cmd --permanent --add-port=143/tcp
firewall-cmd --permanent --add-port=993/tcp
firewall-cmd --permanent --add-port=995/tcp

DNS / NTP

firewall-cmd --permanent --add-port=53/tcp
firewall-cmd --permanent --add-port=53/udp
firewall-cmd --permanent --add-port=123/udp

 


3. firewalld 룰 영구 반영 및 확인

3-1. 룰 반영

firewall-cmd --reload

3-2. 등록된 포트 확인

firewall-cmd --list-ports

또는 전체 확인:

firewall-cmd --list-all

3-3. 포트 제거 방법

예시:

firewall-cmd --permanent --remove-port=8082/tcp
firewall-cmd --reload

SSH 제거 시 주의:

firewall-cmd --permanent --remove-port=22/tcp

원격 접속 중이라면 세션이 끊길 수 있다.


4. iptables 확인 시 firewalld 체인이 보이는 이유

firewalld를 사용하면 내부적으로 iptables 또는 nftables backend를 사용한다.

따라서 아래와 같은 체인이 생성되는 것은 정상 동작이다.

iptables -L -n

예시:

IN_public
PRE_public
FWDI_public
INPUT_ZONES

이 체인들은 firewalld가 자동으로 관리하는 기본 체인이다.

즉:

firewalld 사용
↓
iptables backend 사용
↓
자동 체인 생성

구조로 동작한다.

따라서 체인이 존재한다고 해서 iptables가 별도로 활성화된 것은 아니다.


5. iptables 룰이 남아있다면 확인할 것

iptables에 예상하지 못한 ACCEPT rule이 존재한다면 다른 프로세스가 생성했을 가능성이 있다.

대표적인 예시는 아래와 같다.

firewalld IN_public, PRE_public 체인 생성
Docker DOCKER, DOCKER-USER 체인 생성
libvirt/KVM virbr0 생성

5-1. libvirt/KVM 예시

아래와 같은 규칙은 대부분 libvirt 기본 NAT 네트워크이다.

virbr0
X.X.X.0/24
udp dpt:53

이는 VM 내부 네트워크용 DNS / DHCP 규칙이다.

확인:

virsh net-list --all

5-2. 실제 열린 포트 확인

iptables 체인 존재 여부보다 중요한 것은 실제 허용 포트이다.

확인:

firewall-cmd --list-ports

또는:

iptables-save | grep dport

실제 서비스 포트만 열려 있다면 정상 상태이다.


마무리

iptables를 직접 수정하면서 firewalld도 함께 사용하는 경우 정책 충돌이 자주 발생한다.

운영 환경에서는 다음 중 하나로 통일하는 것이 좋다.

  • iptables 직접 관리
  • firewalld 기반 관리

최근 배포판에서는 대부분 firewalld 기반 관리가 일반적이며, 내부적으로 iptables 체인이 생성되는 것은 정상 동작이다.

728x90