nftables가 삭제된 패킷을 기록하도록 하려면 어떻게 해야 합니까?

nftables가 삭제된 패킷을 기록하도록 하려면 어떻게 해야 합니까?

nftables가 거부된 트래픽만 기록하는 대신 허용되는 모든 수신 트래픽을 기록하도록 만든 것 같습니다. "다른 모든 항목을 거부하고 기록합니다"라고 말하는 다른 방법을 알 수 없습니다.

/etc/nftables.conf파일은 다음과 같습니다.

#!/usr/sbin/nft -f

flush ruleset

table inet filter {
  chain input {
    type filter hook input priority 0;

    # Accept any localhost traffic
    iif lo accept

    # Accept traffic originated from us
    ct state established,related accept

    # Accept neighbour discovery otherwise IPv6 connectivity breaks
    ip6 nexthdr icmpv6 icmpv6 type { nd-neighbor-solicit, nd-router-advert, nd-neighbor-advert } accept

    # Allow incoming SSH connections
    tcp dport ssh ct state new counter accept

    # Allow mdns from the LAN
    ip saddr 192.168.1.0/24 udp dport mdns counter accept
    ip6 saddr fe80::/10 udp dport mdns counter accept

    ip saddr 192.168.1.0/24 log prefix "Rejected: " flags all reject comment "send rejection to LAN only"
    ip6 saddr fe80::/10 log prefix "Rejected: " flags all reject comment "send rejection to LAN only"

    # Log and drop any other traffic
    # THIS IS THE BROKEN PART
    log prefix "Dropped:  " flags all drop
  }
  chain forward {
    type filter hook forward priority 0;
  }
  chain output {
    type filter hook output priority 0;
  }
}

답변1

체인의 기본값에 대한 부분을 놓친 것 같습니다. 에서매뉴얼:

{add | create} chain [family] table chain [{ type type hook hook [device device] priority priority ; [policy policy ;] }]

여기에 언급된 값 은 policy다음과 같이 설명됩니다.

기본 체인을 사용하면 체인의 policy, 즉 포함된 규칙에서 명시적으로 허용되거나 거부되지 않은 패킷에 어떤 일이 발생하는지 설정할 수 있습니다. 지원되는 정책 값은 accept(기본값) 또는 입니다 drop.

따라서 다음 줄을 전환하고 싶을 것입니다.

  chain input {
    type filter hook input priority 0;

이것들을 위해:

  chain input {
    type filter hook input priority 0;
    policy drop;

하지만 규칙에 따라 자신이 갇힐 경우를 대비해 이 컴퓨터에 액세스할 수 있는 방법이 있는지 확인하세요. 사용할 iptables명령은 이지만 iptables-apply그 대신에 무엇을 사용할 수 있는지 잘 모르겠습니다 nft. iptables-apply주어진 시간 초과 기간 내에 호스트에 (여전히) 액세스할 수 있는지 확인할 수 없는 경우 규칙을 되돌립니다.

답변2

나는 결국 LAN 전용 규칙을 위한 별도의 체인으로 점프하여 input체인에 로그 라인이 하나만 있도록 하여 이 문제를 해결했습니다. @0xC0000022L에서 제안한 대로 체인 policy drop에 추가하는 것만으로는 충분하지 않은 이유가 무엇인지 잘 모르겠습니다 .input

#!/usr/sbin/nft --file

flush ruleset

table inet filter {
  chain input {
    type filter hook input priority 0
    policy drop
    # Normal "prelude" things you always want.
    ct state vmap {
      new: continue,
      established: accept,
      related: accept,
      invalid: drop
    }
    ct status dnat  accept
    iiftype loopback  accept
    icmp type echo-request  accept
    icmpv6 type {
      echo-request,
      nd-neighbor-solicit,
      nd-router-advert,
      nd-neighbor-advert
    } accept

    tcp dport ssh accept comment "Allow incoming SSH connections"

    ip  saddr 192.168.1.0/24  jump lan_only
    ip6 saddr fe80::/10       jump lan_only

    log prefix "Dropped:  " flags all drop comment "non-LAN gets dropped brusquely"
  }

  chain lan_only {
    udp dport mdns counter accept comment "Allow mdns from the LAN"
    log prefix "Rejected: " flags all reject comment "LAN gets rejected politely (others get dropped brusquely)"
  }

  chain forward {
    type filter hook forward priority 0
  }
  chain output {
    type filter hook output priority 0
  }
}

관련 정보