-1

I am having two private IP attached to an interface.

inet 10.255.0.127/24 brd 10.255.0.255 scope global eth1
inet 10.255.0.153/24 brd 10.255.0.255 scope global secondary eth1

When traffic leaves the eth1 interface it uses 10.255.0.127 (primary) as the src IP.

How can I change the src IP to use 10.255.0.153 (secondary) based on specific destination. For example if destination is 10.11.0.0/24 it should use 10.255.0.153 and for everything else 10.255.0.127 for the same interface eth1.

Supratik
  • 2,154
  • 10
  • 51
  • 66
  • 2
    you could add static route. 10.11.0.0/24 via 10.255.0.153 dev eth1 and then for the rest: default via 10.255.0.127 dev eth1 – Danila Ladner Feb 01 '14 at 05:54

1 Answers1

0

In addition to a static route, you can use iptables to achieve the desired source address:

iptables -t nat -I POSTROUTING -o eth0 -d 10.11.0.0/24 -s 10.255.0.127 -j SNAT --to-source 10.255.0.153
David Houde
  • 3,200
  • 1
  • 16
  • 19