iptables 에 GeoIP를 적용해보자.

Rockylinux 8.x 에서는 iptables geoip module 을 제공하고 있지 않고 있어 설치 방법을 기록한다.

Rockylinux 에서 iptables 외 firewalld, nftables 를 제공하고 있지만, 개인적으로 가장 익숙한 iptables에 geoip를 적용하는 방법을 알아보도록 한다.

iptables geoip module Install

dnf 레포지토리 추가

앞서 말한것처럼 Rockylinux 기본 레포지토리에서는 페키지를 제공하고 있지 않아 epelrpmfusion 레포지토리를 추가해준다.

rpmfusion은 RHEL 계열 배포판에서 제공되지 않는 추가 패키지를 제공하는 저장소이다. 비상업적 패키지를 제공하는 rpmfusion-free 와 라이선스 제한이 있는 rpmfusion-nonfree 저장소를 제공해준다. 보다 자세한 내용은 https://rpmfusion.org/ 내용 확인을 해보자.

# epel 레포지토리 설치
sudo dnf install epel-release

# rpmfusion 레포지토리 추가
sudo dnf install --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm -E %rhel).noarch.rpm https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-$(rpm -E %rhel).noarch.rpm

# powertools 레포지토리 활성화
sudo dnf config-manager --enable powertools

iptables 확장 모듈 설치

xtables-addons는 geoip 외 추가 기능이 있다.

  1. xt_geoip: IP 주소의 지리적 위치를 확인하는 기능
  2. xt_quota2: 사용자 또는 그룹의 네트워크 사용량을 제한하는 기능
  3. xt_recent: 최근에 연결한 IP 주소를 추적하고, 일정 시간 동안 연결을 차단하는 기능
  4. xt_TARPIT: TCP 연결을 늦추는 기능
  5. xt_osf: OS Fingerprinting을 수행하여, 네트워크 트래픽을 분석하는 기능
# iptables 확장 모률 설치
## xtables-addons는 xt_geoip,xt_quota2,xt_recent,xt_TARPIT,xt_osf 기능을 제공한다.

sudo dnf install xtables-addons

geoip 적용

xt_geoip_dl 이라는 명령어로 csv 데이터베이스를 다운로드 후 xt_geoip_build 를 사용해서 csv 파일 dat 파일로 변환해준다.

# GeoIP DB 다운로드
sudo /usr/libexec/xtables-addons/xt_geoip_dl

# GeoIP DB 적용(오류시 perl 모듈을 설치 필요)
sudo /usr/libexec/xtables-addons/xt_geoip_build -D /usr/share/xt_geoip *.csv
xt_geoip_build 오류시

perl 모듈이 설치되어 있지 않았을때. 오류발생을 해결하기 위해선 perl cpanm 을 사용해서 perl 모듈을 설치해준다.

cpanm 은 perl 의 모듈을 설치하는 CPAN의 클라이언트로 모듈 설치시 필요한 의존성을 자동으로 처리해준다.

# 오류 메시지

Can't locate Net/CIDR/Lite.pm in @INC (you may need to install the Net::CIDR::Lite module) (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at /usr/libexec/xtables-addons/xt_geoip_build line 9.
BEGIN failed--compilation aborted at /usr/libexec/xtables-addons/xt_geoip_build line 9.

Can't locate Text/CSV_XS.pm in @INC (you may need to install the Text::CSV_XS module) (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at /usr/libexec/xtables-addons/xt_geoip_build line 12.
BEGIN failed--compilation aborted at /usr/libexec/xtables-addons/xt_geoip_build line 12.
# xt_geoip_build 사용을 위해 perl 모듈 설치
# perl cpanm 설치
sudo dnf install perl-App-cpanminus

# perl module 설치
sudo cpanm Net::CIDR::Lite
sudo cpanm Text::CSV_XS

iptables 에서 사용하는 방법

# iptables GeoIP 적용예시
sudo iptables -A SSHD -p tcp --dport 22 -m geoip --src-cc KR -j ACCEPT

RHEL 계열에서 리모트 Device의 NetBIOS 이름 알아보기

외부 단말의 NetBIOS 이름을 찾아보고 싶었다. RHEL OS 에서는 nmblookup 과 nbtscan 이라는 명령어로 확인 할 수 있다.

    1. nmblookup

    samba-client 패키지에 포함되어 있다.

    ~]$ sudo dnf install samba-client
    ~]$ nmblookup -A 192.168.2.123
    Looking up status of 192.168.2.123
            MACBOOKPRO-212C <00> -         H <ACTIVE> 
    
            MAC Address = BC-D0-74-5F-21-2C

    2. nbtscan

    nbtscan 은 epel 저장소에 있는 패키지이다. epel 저장소를 활성화 후 ntbscan 패키지 설치하면 된다.

    ]$ sudo dnf install -y epel-release
    ...
    ]$ sudo dnf install -y nbtscan
    ]# nbtscan 192.168.2.123
    Doing NBT name scan for addresses from 192.168.2.123
    
    IP address       NetBIOS Name     Server    User             MAC address      
    ------------------------------------------------------------------------------
    192.168.2.123    MACBOOKPRO-212C            <unknown>        bc-d0-74-5f-21-2c
    
    ]$ sudo nbtscan  -r 192.168.3.0/24
    [sudo] password for poorog: 
    Doing NBT name scan for addresses from 192.168.3.0/24
    
    IP address       NetBIOS Name     Server    User             MAC address      
    ------------------------------------------------------------------------------
    192.168.3.57     DESKTOP-NDPPBIF  <server>  <unknown>        08-62-xx-xx-64-86
    192.168.3.112    DESKTOP-JFUABTI  <server>  <unknown>        bc-f1-xx-xx-ed-c7
    192.168.3.49     IMAC-D4CA85                <unknown>        24-f6-xx-xx-21-12
    192.168.3.26     MACBOOKPRO-A602            <unknown>        14-7d-xx-xx-a6-02
    192.168.3.118    DESKTOP-1VBEIFK  <server>  <unknown>        cc-15-xx-xx-95-3a

    개인적으로 nbtscan을 선호한다.

    nignx unit 멀티쓰레드 설정

    nginx unit 은 1.21.0 버전부터 python 멀티 쓰레드 설정을 할수 있게 되었다.

    멀티 쓰레드 설정을 위해서 Appliacation 설정에 threads 키를 추가 하고 원하는 숫자(정수) 를 지정하면 된다.

        "applications": {
            "my_app": {
                "type": "python",
                "path": "/path/to/my/app",
                "module": "wsgi",
                "threads": 4
            }
        }

    참고 문서 : https://unit.nginx.org/configuration/#python

    nginx unit 는 쓰레드 기반의 아키텍처를 사용하기 때문에 python GIL(글로벌 인터프리터 락)의 영향을 받지 않는다고 한다. https://github.com/nginx/unit/issues/33

    winget 모든? 패키지 업그래이드

    windows의 winget을 사용하면 편한점이 많다.

    winget upgrade 명령하면 아래 처럼 설치된 패키지의 최신 버전을 확인 할수 있다.

    > winget upgrade
    이름                                                    장치 ID                      버전          사용 가능     원본
    -----------------------------------------------------------------------------------------------------------------------
    Termius 8.0.2                                           Termius.Termius              8.0.2         8.0.4         winget
    Mozilla Firefox (x64 ko)                                Mozilla.Firefox              112.0         117.0         winget
    TeamViewer Host                                         TeamViewer.TeamViewer.Host   15.44.5       15.45.3       winget
    Microsoft Visual C++ 2015-2019 Redistributable (x64) -… Microsoft.VCRedist.2015+.x64 14.29.30139.0 14.38.32919.0 winget
    Microsoft Visual C++ 2015-2019 Redistributable (x86) -… Microsoft.VCRedist.2015+.x86 14.22.27821.0 14.38.32919.0 winget
    Microsoft Visual Studio Code (User)                     Microsoft.VisualStudioCode   1.78.2        1.81.1        winget
    PowerToys (Preview) x64                                 Microsoft.PowerToys          0.70.1        0.73.0        winget
    7 업그레이드를 사용할 수 있습니다.

    패키지를 업그래이드 할때는 ? winget upgrade {장치ID} 을 입력 하면 원하는 패키지를 업업그래이드 가능하다.

    > winget upgrade  Microsoft.VisualStudioCode
    찾음 Microsoft Visual Studio Code [Microsoft.VisualStudioCode] 버전 1.81.1
    이 응용 프로그램의 라이선스는 그 소유자가 사용자에게 부여했습니다.
    Microsoft는 타사 패키지에 대한 책임을 지지 않고 라이선스를 부여하지도 않습니다.
    다운로드 중 https://az764295.vo.msecnd.net/stable/6c3e3dba23e8fadc360aed75ce363ba185c49794/VSCodeUserSetup-x64-1.81.1.exe
      ██████████████████████████████  89.0 MB / 89.0 MB
    설치 관리자 해시를 확인했습니다.
    패키지 설치를 시작하는 중...
    설치 성공

    모든 패키지를 업그레이드 하고 싶으면? winget upgrade –all 명령어로 손쉽게 새로운 버전이 있는 모든 패키지 업그레이드가 가능하다.

    > winget upgrade --all
    이름                                                    장치 ID                      버전          사용 가능     원본
    -----------------------------------------------------------------------------------------------------------------------
    Termius 8.0.2                                           Termius.Termius              8.0.2         8.0.4         winget
    Mozilla Firefox (x64 ko)                                Mozilla.Firefox              112.0         117.0         winget
    TeamViewer Host                                         TeamViewer.TeamViewer.Host   15.44.5       15.45.3       winget
    Microsoft Visual C++ 2015-2019 Redistributable (x64) -… Microsoft.VCRedist.2015+.x64 14.29.30139.0 14.38.32919.0 winget
    Microsoft Visual C++ 2015-2019 Redistributable (x86) -… Microsoft.VCRedist.2015+.x86 14.22.27821.0 14.38.32919.0 winget
    PowerToys (Preview) x64                                 Microsoft.PowerToys          0.70.1        0.73.0        winget
    6 업그레이드를 사용할 수 있습니다.
    
    (1/6) 찾음 Termius [Termius.Termius] 버전 8.0.4
    이 응용 프로그램의 라이선스는 그 소유자가 사용자에게 부여했습니다.
    Microsoft는 타사 패키지에 대한 책임을 지지 않고 라이선스를 부여하지도 않습니다.
    다운로드 중 https://autoupdate.termius.com/windows/Install%20Termius.exe
      ██████████████████████████████   165 MB /  165 MB
    설치 관리자 해시가 일치하지 않습니다.
    
    (2/6) 찾음 Mozilla Firefox [Mozilla.Firefox] 버전 117.0
    이 응용 프로그램의 라이선스는 그 소유자가 사용자에게 부여했습니다.
    Microsoft는 타사 패키지에 대한 책임을 지지 않고 라이선스를 부여하지도 않습니다.
    다운로드 중 https://download-installer.cdn.mozilla.net/pub/firefox/releases/117.0/win64/en-US/Firefox%20Setup%20117.0.exe
      ██████████████████████████████  55.5 MB / 55.5 MB
    설치 관리자 해시를 확인했습니다.
    패키지 설치를 시작하는 중...
    설치 성공
    ... 생략 ....

    출처 : https://learn.microsoft.com/ko-kr/windows/package-manager/winget/