운영체제

firewalld PREROUTING 전에 ip 차단 방법

페이지 정보

작성자 DocsArchives
작성일 2025.09.07 20:55
분류 rhel
837 조회

본문

1. ipset 셋 생성


ipset create myblocklist hash:net


myblocklist: set 이름


hash:net: IP 대역(CIDR)을 허용하는 타입


???? hash:ip은 단일 IP만 저장 가능

???? hash:net은 IP 대역 (예: 192.168.0.0/24) 저장 가능


2. IP 대역 추가


ipset add myblocklist 192.168.100.0/24
ipset add myblocklist 10.10.0.0/16

3. iptables 또는 firewalld에 적용

iptables 직접 사용하는 경우:

iptables -I INPUT -m set --match-set myblocklist src -j DROP

이렇게 하면 myblocklist에 포함된 IP 또는 대역에서 들어오는 요청은 모두 DROP 됩니다.

firewalld와 함께 사용하는 경우:

firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -m set --match-set myblocklist src -j DROP
firewall-cmd --reload

ipset 상태 확인
ipset list myblocklist

영구 적용을 위해

ipset은 기본적으로 비영구적입니다. 시스템 재부팅 후 유지하려면 수동 저장 및 복원이 필요합니다.

1. 저장

ipset save > /etc/ipset.conf


2. 부팅 시 복원 설정 (예: systemd)

/etc/systemd/system/ipset-restore.service 예제:



[Unit]
Description=Restore ipset rules
Before=firewalld.service

[Service]
Type=oneshot
ExecStart=/sbin/ipset restore < /etc/ipset.conf

[Install]
[code=bash]systemctl enable ipset-restore
WantedBy=multi-user.target [/code]

정리


작업명령
IP 대역용 set 생성ipset create myblocklist hash:net
IP 대역 추가ipset add myblocklist 1.2.3.0/24
iptables에 연동iptables -I INPUT -m set --match-set myblocklist src -j DROP
firewalld에 연동firewall-cmd --permanent --direct --add-rule ...
저장 및 복원

ipset save > /etc/ipset.conf + systemd





set 안의 특정 IP 또는 대역 삭제


ipset del [set이름] [IP 또는 대역]



댓글 0
홈으로 전체메뉴
전체 검색
회원가입