按 MAC 過濾流量 - nftables

按 MAC 過濾流量 - nftables

翻譯:博士:我正在使用必須保留的樹莓派來建立網路分流器隱身。我有一座橋(布0)之間的開關介面(乙太網路0)和工作站(乙太網路1)。

這是我構建它的方式(接受任何建議):

# Create a bridge with the name br0
ip link add "$BRIDGE_INT" type bridge 
# Add the eth0 interface to the bridge
ip link set "$WORKSTATION_INT" master "$BRIDGE_INT" 
# Add the eth1 interface to the bridge
ip link set "$SWITCH_INT" master "$BRIDGE_INT" 

完成此過程後,我插入網路電纜,我可以看到我的乙太網路0在多種協定上洩露其 MAC。

我測試過的

nft add table inet filter
nft add chain inet filter output { type filter hook output priority 0 \; }
nft add rule inet filter output ether saddr "$SWITCH_MAC" drop

仍在 eth0 DHCP -> ARP -> MDNS 上洩漏。

然後我決定設定 DHCP 靜態位址。經過多次嘗試,我找到了正確的配置(接受任何建議):

/etc/network/interfaces
auto eth0
    iface eth0 inet manual
    address 192.168.0.10
    netmask 255.255.255.0
    gateway 192.168.0.254

/etc/dhcpcd.conf
interface eth0
    static ip_address=192.168.0.10/24
    static routers=192.168.0.1
    static domain_name_servers=192.168.0.1 8.8.8.8

此設定不會向網路查詢 dhcp。但 ARP -> MDNS 仍在洩漏。

由於這個專案的目標是具有適應性,我認為最好的解決方案是放棄所有具有 SWITCH_MAC 的東西。但這並不能阻止流量流出。

我注意到我的規則正確地丟棄了我有意發送的帶有 SWITCH_MAC 的資料包,但沒有丟棄作業系統發出的資料包。

結論 即使測試流量被丟棄,作業系統也會洩漏不需要的流量。我懷疑我的問題與此類似:使用 nftables 按 MAC 位址過濾流量 這已經很好地解釋了,但尚未找到解決方案。

相關內容