iptables 문자열 규칙을 nftables로 변환

iptables 문자열 규칙을 nftables로 변환

다음을 수행하여 iptable에서 nftable로 규칙을 마이그레이션하고 있습니다.iptable에서 nftable로 이동

이제 문자열 기반 iptable 규칙과 함께 IP 및 포트 차단 규칙이 거의 없지만 내장된 iptable 변환 규칙을 사용하여 규칙을 iptable에서 nftable로 변환할 수 있지만 문자열 기반 규칙은 iptable에 있었습니다. 번역 후 nftables에 주석이 추가됩니다. 아래는 번역 후 nftable 규칙입니다.

    add rule ip filter INPUT tcp dport 1024-65535 counter accept
    add rule ip filter INPUT udp dport 1024-65535 counter accept
   65535 -j DROP
    # -t filter -A INPUT -p udp -m udp --dport 234 -m string --string abc.exe --algo bm --to 65535 -j DROP
    # -t filter -A INPUT -p udp -m udp --dport 234 -m string --string def.exe --algo bm --to 65535 -j DROP
    # -t filter -A INPUT -p udp -m udp --dport 234 -m string --string hij.exe --algo bm --to 65535 -j DROP
    add rule ip filter INPUT icmp type echo-reply ct state new,related,established  counter accept
    add rule ip filter INPUT icmp type echo-request ct state new,related,established  counter accept
    add rule ip filter INPUT icmp type destination-unreachable ct state new,related,established  counter accept
    add rule ip filter INPUT icmp type time-exceeded ct state new,related,established  counter accept

문자열 기반 iptable 규칙을 nftable 규칙으로 변환하는 방법에 대한 도움이 필요하며, 위와 같이 실패할 경우 어떤 로그를 참조해야 합니까?

답변1

있다현재는 아니요 nftables와 동일,일치하는 항목은 현재 지원되지 않는 확장 프로그램 목록에 있습니다. 이러한 지원되지 않는 모든 확장 프로그램(및 아마도 일부 지원되는 확장 프로그램)은 다음 언어로 번역되지 않습니다.nftables말로는 표현할 수 없는 특수한 특성을 사용하기 때문입니다.nftables바이트코드( nft -a --debug=netlink list ruleset바이트코드를 보려고 시도)도 커널에서 기본으로 구현되지 않았습니다.nftables모듈이므로 번역 도구는 시도조차 하지 않습니다.

프로토콜에 대해 더 많이 알고 있고 다음 위치에서 문자열을 찾을 수 있을 것으로 예상되는 경우결정된패킷의 위치를 ​​사용하여 동일한 작업을 수행하는 해결 방법이 있습니다.원시 페이로드 표현식거기 예.

그렇지 않으면 그냥 섞을 수 있습니다nftables그리고iptables(포함iptables-nft) 다른 테이블 이름을 사용하는 한 규칙nftables충돌하지 않도록iptables-nft(아마도 사용 중일 것입니다). 아직 단계적으로 폐지할 계획은 없습니다iptables(적어도iptables-nft구현, 다음과 같은 다양한 xtables 모듈을 완벽하게 사용할 수 있습니다.).

여기서는 테이블이 t선택되었으므로 테이블과 충돌하지 않습니다 filter.nftables입력 체인을 얻습니다(임의로 호출됨).c_in우선순위 10에서iptables같은 위치에 연결되는 의 INPUT 체인은 고정된 우선순위 0에서 우선순위를 갖습니다. 우선순위를 0으로 두면 체인(iptables' 또는nftables')가 먼저 실행됩니다. 테이블 간 규칙을 삭제/수락하는 것은 중요하지 않습니다. 중요한 경우는 여기에서 수행된 것처럼 규칙을 분할할 때(그러나 이 특정 경우에는 순서에 특별한 것이 없으므로 괜찮습니다) 규칙이나 부작용이 있는 규칙을 변경하는 경우입니다.nftables 세트또는iptables동반자IP세트그런 다음 패킷을 삭제하는 것은 패킷을 먼저 삭제한 다음 아무 것도 삭제하지 않는 것과 다릅니다.

nft add table ip t
nft add chain ip t c_in '{ type filter hook input priority 10; policy accept; }'

nft add rule ip t c_in tcp dport 1024-65535 counter accept
nft add rule ip t c_in udp dport 1024-65535 counter accept
nft add rule ip t c_in icmp type echo-reply ct state new,related,established  counter accept
nft add rule ip t c_in icmp type echo-request ct state new,related,established  counter accept
nft add rule ip t c_in icmp type destination-unreachable ct state new,related,established  counter accept
nft add rule ip t c_in icmp type time-exceeded ct state new,related,established  counter accept

iptables -t filter -A INPUT -p udp -m udp --dport 234 -m string --string abc.exe --algo bm --to 65535 -j DROP
iptables -t filter -A INPUT -p udp -m udp --dport 234 -m string --string def.exe --algo bm --to 65535 -j DROP
iptables -t filter -A INPUT -p udp -m udp --dport 234 -m string --string hij.exe --algo bm --to 65535 -j DROP

죄송합니다. 다음 문제에 대해 어떻게 해야 할지 모르겠습니다.

   65535 -j DROP

이는 도구의 오타나 번역 오류인 것 같습니다.

두 세계 간의 상호 작용이 필요한 경우 다음을 사용하여 "메시지"를 전달할 수 있습니다.점수. 우선순위가 중요한 경우입니다. 예를 들어, 놓기 작업을 다음 위치에서만 수행해야 하는 경우nftables규칙 관리상의 이유로 이 방법을 대신 사용할 수 있습니다.iptables' 필터/INPUT이 우선순위를 갖습니다.nftables' 여기에는 없습니다:

iptables -t filter -A INPUT -p udp -m udp --dport 234 -m string --string abc.exe --algo bm --to 65535 -j MARK --set-mark 0xdead
iptables -t filter -A INPUT -p udp -m udp --dport 234 -m string --string def.exe --algo bm --to 65535 -j MARK --set-mark 0xdead
iptables -t filter -A INPUT -p udp -m udp --dport 234 -m string --string hij.exe --algo bm --to 65535 -j MARK --set-mark 0xdead

그리고 이것을 삽입하세요.nftables...established...장소에서 단락 규칙보다 먼저 규칙을 정하십시오 .처음에는 규칙이 다음과 같았습니다.

nft add ip t c_in meta mark 0xdead drop

관련 정보