Routing outbound IP packets on multihomed box

Christopher Cowart ccowart at
Sat Jun 16 04:34:27 UTC 2007

On Fri, Jun 15, 2007 at 05:35:33PM -0700, Julian Elischer wrote:
> Christopher Cowart wrote:
> >On Fri, Jun 15, 2007 at 06:30:23PM -0400, Boris Kochergin wrote:
> >>Christopher Cowart wrote:
> >>>I have a server with two NICs:
> >>>
> >>>em0:
> >>>vlan526:
> >>>
> >>>The default gateway is The router for the 126 subnet is
> >>> 
> >>>
> >>>netstat -rn:
> >>>| Destination        Gateway            Flags    Refs      Use  Netif 
> >>>Expire
> >>>| default       UGS         0   102537    em0
> >>>|          UH          0      217    lo0
> >>>|  link#1             UC          0        0    em0
> >>>|     00:15:c7:b9:f4:80  UHLW        2        4    em0   
> >>>1193
> >>>|     00:11:25:ab:42:70  UHLW        1      589    lo0
> >>>| 169.229.126/24     link#9             UC          0        0 vlan52
> >>>|      00:15:c7:b9:f4:80  UHLW        1       34 vlan52   
> >>>1200
> >>>|      00:18:f8:09:d3:a5  UHLW        1        8    lo0
> >>>
> >>>The IP address on em0 works exactly as one would expect. I have full IP
> >>>connectivity to it from other subnets. 
> >>>
> >>>The problem is I can't get 2-way connectivity with the IP address on
> >>>vlan526.
> >>>
> >>>Using my workstation on a third subnet (, I cannot
> >>>ping I leave the ping running and do some tcpdumps on 
> >>>the server.
> >>>
> >>>$ sudo tcpdump -ni vlan526 host
> >>>| 14:14:37.002920 IP > ICMP echo 
> >>>| request, id 15733, seq 35, length 64
> >>>| 14:14:38.003037 IP > ICMP echo 
> >>>| request, id 15733, seq 36, length 64
> >>>
> >>>Notice there are no echo replies. That's because they're being sent 
> >>>here:
> >>>
> >>>$ sudo tcpdump -ni em0 host
> >>>| 14:15:42.006997 IP > ICMP echo reply, 
> >>>| id 15733, seq 100, length 64
> >>>| 14:15:43.007118 IP > ICMP echo reply, 
> >>>| id 15733, seq 101, length 64
> >>>
> >>>I repeated this last snoop with a -w and loaded it into ethereal. The
> >>>echo replies being sent out on em0 indeed have a source address of
> >>> The router ( drops these packets on the
> >>>floor, because their source address isn't routable on that interface.
> >>>
> >>>Because routing is based on destination, not source address, I'm not
> >>>sure how to get packets sourced from the 126 subnet to the router on the
> >>>126 subnet. I tried the following ipfw rule right after allow loopback
> >>>traffic (my second rule):
> >>>
> >>>fwd ip from to not
> >>>
> >>>Still no luck. Has anyone set up a multihomed box on *different* subnets
> >>>before without routing them through the FreeBSD box? Does anyone have
> >>>any pointers or things I should be looking at?
> >>Hi. I've come across this problem but solved it with a PF rule of this 
> >>form, if that's an option for you:
> >>
> >>pass out route-to (vlan256 from to any
> >>
> >>This tells PF to send all packets sent from through the 
> >>vlan256 interface with a next-hop address of
> >
> >Unfortunately, I don't think we can use pf. The rest of our
> >infrastructure is ipfw and we don't particularly want this to be a
> >one-off. I was under the impression that my ipfw rule did exactly this,
> >by sending the packets to the 126 router as their next hop.
> >
> >Anyone have any ideas on whether an ipfw fwd rule can be used in a
> >similar way to this pf rule?
> >
> >Thanks again,
> >
> he ipfw rule should work, assuming you have the IPFIREWALL_FORWARDING option
> (and it's not the couple of versions of the OS where you also needed the

I had forwarding enabled, but not the EXTENDED flag. Apparently
bypassing the routing table in the firewall is an "unsafe" practice. Now
I can source traffic from the vlan526 interface correctly. Thanks!

> also, you need to make it an 'out' rule..i.e. 
> fwd ip from to not out

This doesn't appear to be necessary...

The next step, and here I'm having more problems, is I want to NAT
traffic using the vlan526 interface.

Using the same configuration as above, I've added:

When a NAT'd client pings off the 126 subnet (say,, 
the packets go out em0 again.

My ipfw ruleset looks like this:
allow all from any to any via lo0
divert natd ip from not me to any via
fwd ip from to not
allow icmp from any to any

My understanding of divert is that after natd munges the packets,
they'll return to the ipfw rules immediately following rule 13. In this
case, traffic appearing from the NAT ip address should be forwarded to
the 126 router on the next-hop.

When I do `tcpdump -ni em0 host`, I notice the outbound
ICMP echo requests have src-addr of 10.80.x.x (IP address of the nat'd
client). Does this mean that as ipfw continues processing the packet,
even after natd has munged it, that as far as ipfw is concerned, the
src-addr of the packet hasn't changed?

In other words, would I need to write a complicated set of rules that do
something like:
divert natd ip from not me to any via
fwd ip from to not
fwd ip from to not

Any recommendations on how to solve the NATing extension of this routing

Thanks again,

Chris Cowart
Lead Systems Administrator
Network Infrastructure, RSSP-IT
UC Berkeley
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url :

More information about the freebsd-net mailing list