Subject: Re: Setting outgoing packet's source address
To: Michal Ludvig <michal@logix.cz>
From: Karim Belbachir <karim@xuthal.net>
List: netbsd-users
Date: 08/19/2003 18:05:11
On Tue, Aug 19, 2003 at 05:18:47PM +0200, Michal Ludvig wrote:
> Hi all,
> is there a way in NetBSD to specify a source IP address of an outgoing 
> packet?
> Example:
> I have a machine on a network 10.0.0.0/16 with two addresses: 10.0.1.1 
> and 10.0.2.1. By default I want to use 10.0.1.1 for my outgoing traffic, 
> but when accessing any host from a sub-network 10.0.2.0/24 I want to use 
> address 10.0.2.1. Can I somehow do this?
> In Linux I can use 'ip route add 10.0.2.0/24 dev eth0 src 10.0.2.1' - is 
> there an equivalent in NetBSD?

The following command should do the job:
route add -net 10.0.2.0 -netmask 255.255.255.0 -interface 10.0.2.1