首页 > 解决方案 > 在同一子网上配置 2 个 NIC

问题描述

出于调试目的,我需要在 2 个设备之间设置 MITM 代理。所有设备都具有静态 IP(示例)并且彼此直接连接:

Device 1 : 192.168.10.50
Device 2 : 192.168.10.60

代理计算机在同一子网上有 2 个网卡,并且位于其他设备之间:
D1 .50 <=> [.60 PROXY .50] <=> D2 .60

我的问题是,如果 2 个 nic 之一被禁用,则 D1 或 D2 可以从代理访问代理。
一旦我调出 2 nic,没有人可以看到任何其他设备。D1 和 D2 ip 不能更改。

代理是linux centos 8。

已经测试过:

如果有人可以提供帮助。
谢谢 。

标签: networkingiptables

解决方案


我找到了一个解决方案,它包括创建一个透明代理并拦截一些数据包。

1-使用 2 个 NIC 创建一个网桥:

nmcli connection add type bridge autoconnect yes con-name "br0" ifname "br0"
nmcli connection modify "br0" ipv4.addresses "192.168.10.10/24" ipv4.method manual
nmcli connection delete enp0s3
nmcli connection delete enp0s8
nmcli connection add type bridge-slave autoconnect yes con-name enp0s3 ifname enp0s3 master br0
nmcli connection add type bridge-slave autoconnect yes con-name enp0s8 ifname enp0s8 master br0

2 添加正确的规则拦截特定流量

nft add table bridge mitm
nft add chain bridge mitm filter { type filter hook prerouting priority 0\; }
nft add rule bridge mitm filter tcp dport 10000 ip saddr 192.168.10.50 meta pkttype set host ether daddr set xx:xx:xx:xx:xx:xx # br0 mac address
nft add rule ip nat PREROUTING tcp dport 10000 ip saddr 192.168.10.50 dnat to 192.168.10.10

它对我有用。


推荐阅读