42.4. nftables 스크립트 작성 및 실행
nftables 프레임워크를 사용할 때의 주요 이점은 스크립트 실행이 atomic이라는 것입니다. 즉, 시스템이 전체 스크립트를 적용하거나 오류가 발생하면 실행을 방지합니다. 이렇게 하면 방화벽이 항상 일관된 상태로 유지됩니다.
또한 nftables 스크립트 환경을 사용하면 다음을 수행할 수 있습니다.
- 댓글 추가
- 변수 정의
- 기타 규칙 세트 파일 포함
nftables 패키지를 설치하면 Red Hat Enterprise Linux가 /etc/nftables/ 디렉터리에 *.nft 스크립트가 자동으로 생성됩니다. 이러한 스크립트에는 서로 다른 용도로 테이블 및 빈 체인을 만드는 명령이 포함되어 있습니다.
42.4.1. 지원되는 nftables 스크립트 형식 링크 복사링크가 클립보드에 복사되었습니다!
nftables 프레임워크는 다른 형식의 스크립트를 지원합니다.
다음 형식을 사용할 수 있습니다.
nft list ruleset명령과 동일한 형식은 규칙 세트를 표시합니다.#!/usr/sbin/nft -f # Flush the rule set flush ruleset table inet example_table { chain example_chain { # Chain for incoming packets that drops all packets that # are not explicitly allowed by any rule in this chain type filter hook input priority 0; policy drop; # Accept connections to port 22 (ssh) tcp dport ssh accept } }nft명령과 동일한 구문:#!/usr/sbin/nft -f # Flush the rule set flush ruleset # Create a table add table inet example_table # Create a chain for incoming packets that drops all packets # that are not explicitly allowed by any rule in this chain add chain inet example_table example_chain { type filter hook input priority 0 ; policy drop ; } # Add a rule that accepts connections to port 22 (ssh) add rule inet example_table example_chain tcp dport ssh accept