설명
이 페이지에서는 CentOS에서 방화벽 설정에 사용된는 ipset 설정에 대해서 살펴보겠습니다.
ipset
설정할 수 있는 「ipset」 타입을 보여 줍니다. 알아보기 쉽게 적당히 개행처리하였습니다. 그럼 많이 사용하는 타입인 hash:ip와 hash:net에 대해서 알아 보겠습니다.
[root@localhost ~]# firewall-cmd --get-ipset-types
hash:ip
hash:ip,mark
hash:ip,port
hash:ip,port,ip
hash:ip,port,net
hash:mac
hash:net
hash:net,iface
hash:net,net
hash:net,port
hash:net,port,net
ipset - hash:ip type
hash:ip는 IP와 Network 주소를 지원합니다. IPv4의 경우는 「CIDR prefix value」가 1에서 32 사이여야만 한다는 조건이 있기 때문에 단일 네트워크 또는 단일 네트워크의 IP를 추가할 때 유용할 수 있습니다. IPv6의 경우는 1에서 128 까지로 제한됩니다.
hash:ip 타입으로 ipset 추가하고, 이어서 Network 주소 및 IP를 추가해 보겠습니다.
[root@localhost ~]# firewall-cmd --permanent --new-ipset=test_internal_https --type=hash:ip
※「--new-ipset=」에 적당히 네이밍을 합니다.
[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --add-entry=192.168.56.0/27
[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --add-entry=192.168.56.33
[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --add-entry=192.168.56.34
[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --add-entry=192.168.56.35
위에서 추가한 ipset 정보를 확인합니다.
[root@localhost ~]# firewall-cmd --get-ipsets
ipset에 추가한 단일 엔트리의 유무도 확인할 수 있습니다.
[root@localhost ~]# firewall-cmd --ipset=test_internal_https --query-entry=192.168.56.35
yes
[root@localhost ~]# firewall-cmd --ipset=test_internal_https --query-entry=192.168.56.40
no
다음은 엔트리를 삭제해 보겠습니다. 그런다음 파일에서 엔트리를 추가해 보겠습니다.
[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --remove-entry=192.168.56.0/27
[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --remove-entry=192.168.56.33
[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --remove-entry=192.168.56.34
[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --remove-entry=192.168.56.35
[root@localhost ~]# firewall-cmd --reload
[root@localhost ~]# firewall-cmd --ipset=test_internal_https --get-entries
Nothing...
[root@localhost ~]# echo -e "192.168.56.33\n192.168.56.34\n192.168.56.35\n192.168.56.0/27" > /root/test_internal_https_hash_ip.txt
[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --add-entries-from-file=/root/test_internal_https_add_hash_ip.txt
[root@localhost ~]# firewall-cmd --reload
[root@localhost ~]# firewall-cmd --ipset=test_internal_https --get-entries
192.168.56.33
192.168.56.34
192.168.56.35
192.168.56.0/27
파일로 일부 엔트리를 삭제해 보고, ipset 자체를 삭제해 보겠습니다.
[root@localhost ~]# echo "192.168.56.34" > /root/test_internal_https_rem_hash_ip.txt
[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --remove-entries-from-file=/root/test_internal_https_rem_hash_ip.txt
[root@localhost ~]# firewall-cmd --reload
[root@localhost ~]# firewall-cmd --ipset=test_internal_https --get-entries
192.168.56.33
192.168.56.35
192.168.56.0/27
[root@localhost ~]# firewall-cmd --permanent --delete-ipset=test_internal_https
[root@localhost ~]# firewall-cmd --reload
[root@localhost ~]# firewall-cmd --get-ipsets
Nothing...
ipset - hash:net type
hash:net는 복수의 네트워크 주소를 추가할수 있습니다. hash:ip 타입을 지정하는 부분 외에 설정 방법이 거의 같으므로, ipset 생성과 엔트리 추가 외의 부분은 생략하겠습니다.
[root@localhost ~]# firewall-cmd --permanent --new-ipset=test_internal_snmp --type=hash:net
※「--new-ipset=」에 적당히 네이밍을 합니다.
[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_snmp --add-entry=192.168.56.0/24
[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_snmp --add-entry=192.168.57.0/24
[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_snmp --add-entry=192.168.58.0/24
[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_snmp --add-entry=192.168.59.0/24
위에서 추가한 ipset 정보를 확인합니다.
[root@localhost ~]# firewall-cmd --get-ipsets
생성한 ipset의 정보를 확인합니다.
[root@localhost ~]# firewall-cmd --info-ipset=test_internal_snmp
test_internal_snmp
type: hash:net
options:
entries: 192.168.56.0/24 192.168.57.0/24 192.168.58.0/24 192.168.59.0/24
읽어 주셔서 감사합니다.