How do I set the source address on a multi-homed host?

Jan Grant Jan.Grant at
Sun Feb 13 09:37:07 GMT 2005

On Sat, 12 Feb 2005, Daniela wrote:

> Yes, this happens when I connect from my machine (which functions as a router 
> with NAT to allow the other LAN machines connect to the internet) to another 
> LAN machine. When the router establishes a connection to another point in the 
> intranet, the source address used is my official IP, and not, which 
> is the intranet IP of the router.
> In other words, I want the source address to be on every outgoing 
> connection where the destination is inside my intranet.

Assuming you haven't munged the internal IP address to hide it, and with 
all due deference to the FreeBSD "mechanism, not policy" mantra: no, you 
don't want to do this. The block of addresses is explicitly 
for private use and is not routable on the internet.

If your firewall is causing problems with this setup, you might need to 
re-examine your firewall settings.

Having said that: technically, you specify source addresses for 
connections by calling bind(2) prior to calling connect(2). If you fail 
to do this, the operating system will select a source IP address for 
you. This'll often be the IP of the outgoing interface.

Unless your particular application explicitly supports the selection of 
source addresses, you're mostly out of luck. For instance, ping(8) 
supports this (see the -S option).


jan grant, ILRT, University of Bristol.
Tel +44(0)117 9287864 or +44 (0)117 9287088
Bolstered by my success with vi, I proceeded to learn C with 'learn c'.

More information about the freebsd-questions mailing list