nftables가 있는 라우터가 제대로 작동하지 않습니다.

nftables가 있는 라우터가 제대로 작동하지 않습니다.

나는 Debian 4.19.194-1을 라우터 서버로 사용하고 LAN, WAN, PPPOE(게이트웨이) 및 LAN 네트워크의 COMPUTER1을 사용하므로 데비안 라우터를 통해 인터넷에 액세스할 수 있어야 합니다.

방화벽으로 nftables와 규칙을 사용합니다.

#!/usr/sbin/nft -f
flush ruleset

define EXTIF = "ppp0"
define LANIF = "enp1s0"
define WANIF = "enp4s0"
define LOCALIF = "lo"

table firewall {
    chain input {
        type filter hook input priority 0

        ct state {established, related} counter accept
        ct state invalid counter drop

        ip protocol icmp counter accept
        ip protocol igmp counter accept comment "Accept IGMP"
        ip protocol gre counter accept comment "Accept GRE"

        iifname { $LOCALIF, $LANIF } counter accept
        tcp dport 44122 counter accept
        udp dport 11897 counter accept
        udp dport 1194 counter accept
        udp dport {67,68} counter accept comment "DHCP"
        counter reject
    }

    chain forwarding {
        type filter hook forward priority 0

        # teleguide.info for ntf monitor
        ip daddr 46.29.166.30 meta nftrace set 1 counter accept
        ip saddr 46.29.166.30 meta nftrace set 1 counter accept

        udp dport 1194 counter accept
        tcp dport 5938 counter accept
        udp dport 5938 counter accept

        ip daddr 10.10.0.0/24 counter accept
        ip saddr 10.10.0.0/24 counter accept
        ip protocol gre counter accept comment "Accept GRE Forward"

        counter drop comment "all non described Forward drop"
    }

    chain outgoing {
        type filter hook output priority 0
        oifname $LOCALIF counter accept
    }
}

table nat {
    chain prerouting {
        type nat hook prerouting priority 0
        iifname $EXTIF udp dport 1194 counter dnat to 10.10.0.4
    }

    chain postrouting {
        type nat hook postrouting priority 0
        ip saddr 10.10.0.0/24 oifname $EXTIF counter masquerade
    }
}


lsmod:

tun                    53248  2
pppoe                  20480  2
pppox                  16384  1 pppoe
ppp_generic            45056  6 pppox,pppoe
slhc                   20480  1 ppp_generic
binfmt_misc            20480  1
i915                 1736704  0
ppdev                  20480  0
evdev                  28672  2
video                  49152  1 i915
drm_kms_helper        208896  1 i915
iTCO_wdt               16384  0
iTCO_vendor_support    16384  1 iTCO_wdt
parport_pc             32768  0
coretemp               16384  0
sg                     36864  0
serio_raw              16384  0
pcspkr                 16384  0
drm                   495616  3 drm_kms_helper,i915
parport                57344  2 parport_pc,ppdev
i2c_algo_bit           16384  1 i915
rng_core               16384  0
button                 20480  0
nft_masq_ipv4          16384  3
nft_masq               16384  1 nft_masq_ipv4
nft_reject_ipv4        16384  1
nf_reject_ipv4         16384  1 nft_reject_ipv4
nft_reject             16384  1 nft_reject_ipv4
nft_counter            16384  25
nft_ct                 20480  2
nft_connlimit          16384  0
nf_conncount           20480  1 nft_connlimit
nf_tables_set          32768  3
nft_tunnel             16384  0
nft_chain_nat_ipv4     16384  2
nf_nat_ipv4            16384  2 nft_chain_nat_ipv4,nft_masq_ipv4
nft_nat                16384  1
nf_tables             143360  112 nft_reject_ipv4,nft_ct,nft_nat,nft_chain_nat_ipv4,nft_tunnel,nft_counter,nft_masq,nft_connlimit,nft_masq_ipv4,nf_tables_set,nft_reject
nf_nat                 36864  2 nft_nat,nf_nat_ipv4
nfnetlink              16384  1 nf_tables
nf_conntrack          172032  8 nf_nat,nft_ct,nft_nat,nf_nat_ipv4,nft_masq,nf_conncount,nft_connlimit,nft_masq_ipv4
nf_defrag_ipv6         20480  1 nf_conntrack
nf_defrag_ipv4         16384  1 nf_conntrack
ip_tables              28672  0
x_tables               45056  1 ip_tables
autofs4                49152  2
ext4                  745472  2
crc16                  16384  1 ext4
mbcache                16384  1 ext4
jbd2                  122880  1 ext4
fscrypto               32768  1 ext4
ecb                    16384  0
crypto_simd            16384  0
cryptd                 28672  1 crypto_simd
glue_helper            16384  0
aes_x86_64             20480  1
raid10                 57344  0
raid456               172032  0
async_raid6_recov      20480  1 raid456
async_memcpy           16384  2 raid456,async_raid6_recov
async_pq               16384  2 raid456,async_raid6_recov
async_xor              16384  3 async_pq,raid456,async_raid6_recov
async_tx               16384  5 async_pq,async_memcpy,async_xor,raid456,async_raid6_recov
xor                    24576  1 async_xor
raid6_pq              122880  3 async_pq,raid456,async_raid6_recov
libcrc32c              16384  3 nf_conntrack,nf_nat,raid456
crc32c_generic         16384  5
raid0                  20480  0
multipath              16384  0
linear                 16384  0
raid1                  45056  2
md_mod                167936  8 raid1,raid10,raid0,linear,raid456,multipath
sd_mod                 61440  6
ata_generic            16384  0
ata_piix               36864  4
libata                270336  2 ata_piix,ata_generic
psmouse               172032  0
scsi_mod              249856  3 sd_mod,libata,sg
ehci_pci               16384  0
i2c_i801               28672  0
uhci_hcd               49152  0
lpc_ich                28672  0
ehci_hcd               94208  1 ehci_pci
mfd_core               16384  1 lpc_ich
usbcore               299008  3 ehci_pci,ehci_hcd,uhci_hcd
r8169                  90112  0
realtek                20480  2
libphy                 77824  2 r8169,realtek
usb_common             16384  1 usbcore

ntf 모니터 추적(결론은 어디에서나 허용됨):

trace id 2c2a8923 ip firewall forwarding packet: iif "enp1s0" oif "ppp0" ether saddr xxx ether daddr xxx ip saddr 10.10.0.96 ip daddr 46.29.166.30 ip dscp cs0 ip ecn not-ect ip ttl 127 ip id 32611 ip length 52 tcp sport 62489 tcp dport https tcp flags == syn tcp window 8192 
trace id 2c2a8923 ip firewall forwarding rule ip daddr 46.29.166.30 nftrace set 1 counter packets 0 bytes 0 accept (verdict accept)
trace id 2c2a8923 ip nat postrouting packet: oif "ppp0" @ll,xxx ip saddr 10.10.0.96 ip daddr 46.29.166.30 ip dscp cs0 ip ecn not-ect ip ttl 127 ip id 32611 ip length 52 tcp sport 62489 tcp dport https tcp flags == syn tcp window 8192 
trace id 2c2a8923 ip nat postrouting rule ip saddr 10.10.0.0/24 oifname "ppp0" counter packets 0 bytes 0 masquerade (verdict accept)
trace id 73f8f405 ip firewall forwarding packet: iif "ppp0" oif "enp1s0" ip saddr 46.29.166.30 ip daddr 10.10.0.96 ip dscp af32 ip ecn not-ect ip ttl 58 ip id 0 ip length 52 tcp sport https tcp dport 62489 tcp flags == 0x12 tcp window 29200 
trace id 73f8f405 ip firewall forwarding rule ip saddr 46.29.166.30 nftrace set 1 counter packets 0 bytes 0 accept (verdict accept)
trace id ca8ec4f5 ip firewall forwarding packet: iif "enp1s0" oif "ppp0" ether saddr xxx ether daddr xxx ip saddr 10.10.0.96 ip daddr 46.29.166.30 ip dscp cs0 ip ecn not-ect ip ttl 127 ip id 32612 ip length 40 tcp sport 62489 tcp dport https tcp flags == ack tcp window 256 

이유는 모르겠지만 일부 사이트는 COMPUTER1에서 제대로 작동하지만 일부 사이트는 이러한 규칙을 준수하지 않습니다.

예: https://google.com서버와 머신 1에서는 잘 작동하지만 https://teleguide.info서버(wget)에서는 잘 작동하지만 머신 1에서는 작동하지 않습니다.

무슨 문제가 있는지 아시나요?

답변1

방화벽 규칙으로 인해 문제가 발생하지 않았습니다. 오히려 이는 "일반" 이더넷과 PPPoE의 MTU 차이 때문입니다. PPP 헤더는 (최소) 8바이트를 차지하고 이더넷 자체의 일반적인 MTU는 1500바이트이므로 이 경우 PPPoE의 MTU는 최대 1492바이트입니다.

MTU에 대해 자세히는 모르지만, 제가 알고 있는 바로는 TCP SYN 패킷이 광고하는 MSS가 응답이 통과할 인터페이스의 MTU 크기보다 클 경우 응답 트래픽이 실제로 문제를 일으킬 수 있습니다. 온다.

AFAIK, 라우터/서버 자체와 잘 작동하는 이유는 MSS가 아웃바운드 인터페이스( )의 MTU에서 파생되는 ppp0반면 COMPUTER1의 아웃바운드 인터페이스는 일반 이더넷이기 때문입니다.

TCP 트래픽의 경우 hook forwarding체인에 규칙을 추가하면 이 문제를 해결할 수 있습니다.

tcp flags syn tcp option maxseg size set 1452

1452from 1500 - 8 - 40, 여기서 40은 IPv4 헤더의 크기입니다. IPv6의 경우 1500 - 8 - 60= 가 필요할 수 있습니다 1432.

규칙 보다 먼저 규칙을 정렬할 수 있습니다 accept. (이것은 규칙 세트의 전체 구조에 따라 달라질 수 있다고 생각합니다.)

PS UDP 트래픽에 대해 어떤 조치를 취해야 할지 잘 모르겠습니다.


또는 LANIF이 "라우터"(및 모든 LAN "클라이언트")의 이더넷 인터페이스의 MTU를 로 설정할 수 있습니다 1492. 이는 "해결 방법"이 덜한 접근 방식일 수 있지만 문제가 될 수 있습니다.

관련 정보