Using arp_announce

It is possible to control which source address is put in to ARP headers using the ARP_ANNOUNCE option in the kernel.

It takes the following values.

0 (default) Any local address
1 Use address from the same subnet as the target address
2 prefer primary address.

This is worth knowing because the default can give some very strange results when routing packets with linux.

To test this you can run the following command

# sysctl -w net.ipv4.conf.all.arp_announce=1

To make it a permanent solution add a line like this to /etc/sysctl.conf

net.ipv4.conf.all.arp_announce = 1