基于策略的网桥接口路由

我目前正在build立一个带有2个networking接口的Ubuntu 12.04。 eth0位于LAN_USERS(192.168.5.0/24)用于用户,eth1位于LAN_INFRA(10.0.4.0)用于pipe理。 另外,我在eth1上搭build了一座桥梁。

cat /etc/network/interfaces

 auto eth0 iface eth0 inet static address 192.168.5.180 netmask 255.255.255.0 network 192.168.5.0 broadcast 192.168.5.255 gateway 192.168.5.1 auto eth1 iface eth1 inet manual auto br1 iface br1 inet static address 10.0.4.5 netmask 255.255.255.0 network 10.0.4.0 broadcast 10.0.4.255 gateway 10.0.4.1 bridge_ports eth1 bridge_stp on bridge_fd 0 bridge_waitport 0 
  1. 从Ubuntu 12.04开始,启用反向path过滤(rp_filter = 1)
  2. # route -n的输出是:
     Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.5.1 0.0.0.0 UG 100 0 0 eth0 10.0.4.0 0.0.0.0 255.255.255.0 U 0 0 0 br1 192.168.5.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 

由于反向path过滤,br1对10.0.4.0以外的networking不可见。 我可以禁用反向path过滤,但我决定build立基于策略的路由

基于策略的路由

  1. echo "250 infra >> /etc/iproute2/rt_tables
  2. ip rule add iif br1 table infra
  3. ip route add to default dev br1 table infra
  4. 内核configurationvariables:CONFIG_IP_ADVANCED_ROUTER = y和CONFIG_IP_MULTIPLE_TABLES = y
  5. net.ipv4.ip_forward = 0
  6. net.ipv4.conf.eth1.rp_filter = 1
  7. net.ipv4.conf.br1.rp_filter = 1
  8. net.ipv4.conf.all.log_martians = 1

它不工作….

我如何debugging我的PBR规则? 我的设置有任何明显的错误?

干杯

更新:我需要的是路由答复来自br1的数据包再次通过BR1而不是eth0。 我最简单的用例是:从192.168.5.10到10.0.4.5的ping不返回默认路由的原因,rp_filter = 1。 他们作为火星包丢弃。

你的configuration说:“如果一个数据包已经到达br1,然后通过br1发送它。 这显然没有意义。 像这样的规则是路由器,但你甚至不提及路由。

你的意思是:“发送数据包,这是对通过br1到达br1的数据包的回复。” 这可以通过Netfilter的包标记和ip rule选项fwmark 。 但在这里这是没有意义的。 因为您使用rp_filter,您可以简单地按目标地址进行路由。 你甚至不需要高级路由( ip rule )。 为了那个原因。 普通的普通路由应该做这个工作:“通过br1发送10.0.4.0/24,其余通过eth0发送。”

你已经解释了你做了什么,但没有提到任何需要复杂设置的任务。 如果你“什么都不做”特别出什么问题呢?