linux vlan路由

Mea*_*roM 6 linux routing vlan interface

我有这个网络拓扑:

network 192.168.100.0/24 vlan 100
network 192.168.200.0/24 vlan 200
Run Code Online (Sandbox Code Playgroud)

一台 ubuntu 服务器(1 个以太网上的 2 个 vlan)eth0.100(ip:192.168.100.10/24)eth0.200(ip:192.168.200.20/24 def gw 1​​92.168.200.254)

情况如下:

  1. eth0.200 上涨
  2. eth0.100 我们下来。
  3. 来自子网 192.168.100.0/24 的连接可以连接到 192.168.200.20。

当我制作 eth0.100 时:

  • 无法从 192.168.100.0/24 网络访问 192.168.200.20。(错误的接口响应。当包从 192.168.100.0/24 到达 192.168.200.20 时,它被 192.168.100.10 响应)

如何解决这个问题?

尝试使用 rp_filter=0/rp_filter=1

#cat /etc/network/interfaces
iface eth0.200 inet static
    address 192.168.200.20
    netmask 255.255.255.0
    vlan-raw-device eth0
    gateway 192.168.200.254
    post-up ip r a 192.168.200.6 via 192.168.200.250 #one ip behind wifi

iface eth0.100 inet static
    address 192.168.100.10
    netmask 255.255.255.0
    vlan-raw-device eth0
Run Code Online (Sandbox Code Playgroud)

希望与:

iptables -A PREROUTING -t mangle -i eth0.100 -j MARK --set-mark 100
iptables -A PREROUTING -t mangle -i eth0.200 -j MARK --set-mark 200
making some route tables like t100 and t200
and then ading rule like:
ip rule add from all fwmark 100 table t100
ip rule add from all fwmark 200 table t200
Run Code Online (Sandbox Code Playgroud)

它是 RP_FILTER

net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.eth0/100.rp_filter = 0
net.ipv4.conf.eth0/200.rp_filter = 0
Run Code Online (Sandbox Code Playgroud)

phe*_*mer 6

添加我的评论作为答案,以便对其进行标记。

诸如此类的问题是由net.ipv4.conf.*.rp_filter.

rp_filter启用时,内核将拒绝交通未来在流量的源地址在该服务器上其他接口的子网相匹配的接口上。

如果启用该设置上可能会出现很多次的问题net.ipv4.conf.all.rp_filter,而不是像在特定接口net.ipv4.conf.eth0.rp_filter
的默认设置rp_filter0,但是许多发行版会覆盖此设置。因为它是由发行版在启动时手动设置的,在下面设置net.ipv4.conf.all.rp_filter不再有效,必须在特定界面(如net.ipv4.conf.eth0.rp_filter)上设置。