Specifing ip address for outbound connections on a multi ip host

Solution 1:

Update default:

ip route change default via 81.169.180.1 src 81.169.180.51

Check configuration:

ip route list

Solution 2:

The answer by bindbn is good, but I found some complications.

1) You should check "ip route list" as bindbn says. Some other rule in the list may take precedence over the default route. You might need to delete that rule, or create a slightly different rule.

2) All changes done via the ip command only work until next reboot. This answer Permanently adding source policy routing rules explains how to make it persistent.

In summary, you can add the ip route command you need to run as an "up" or "post-up" line to /etc/network/interfaces. You could add a corresponding "down" line to remove the route.

Tags:

Linux

Ip

Routing