0

I have multiple interfaces on my system catering to different subnets. I also have a pseudo interface which is a p-to-p driver for tunneling packets. I was trying to add routes using ip route command to use a specific interfaces' source IP when sending the packets out on the tunnel interface.

In this example, i want to use 11.11.11.1 source IP which is set on eth1.100 when sending packets to 60.60.60.1 which is reachable over the tunnel. This is how my route table looks like.

/tmp # ip route show
60.60.60.1 dev tsgw  scope link  src 11.11.11.1  >> Added this route.
11.11.11.0/24 dev eth1.100  proto kernel  scope link  src 11.11.11.1
default via 192.168.1.254 dev eth1.4094  metric 10
192.168.1.0/24 dev eth1.4094  proto kernel  scope link  src 192.168.1.3 

If i ping 60.60.60.1, it still picks my interface through which default route is programmed.

PING 60.60.60.1 (60.60.60.1): 56 data bytes
19:35:32.848428 IP 192.168.1.3 > 60.60.60.1: ICMP echo request, id 16986, seq 0, length 64
19:35:33.848621 IP 192.168.1.3 > 60.60.60.1: ICMP echo request, id 16986, seq 1, length 64
19:35:34.848819 IP 192.168.1.3 > 60.60.60.1: ICMP echo request, id 16986, seq 2, length 64

Am i doing something wrong with setting the source? Whats the right way to go about this? Basically i am looking to send all packets taking the tsgw interface to use a specific private source IP.

eth1.100  Link encap:Ethernet  HWaddr 00:0B:86:B8:91:10
          inet addr:11.11.11.1  Bcast:11.11.11.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1602  Metric:1
          RX packets:560 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:97395 (95.1 KiB)  TX bytes:704 (704.0 B)


tsgw      Link encap:Point-Point Protocol  
          inet addr:127.0.0.2  P-t-P:127.0.0.2  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:960  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6240 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:1121650 (1.0 MiB)
Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
  • It looks like you have not set up source routing (You need more then 1 table). This topic has been done to death - google "Linux Source Routing", or better go to http://www.lartc.org/lartc.html#LARTC.RPDB.SIMPLE and search for "source routing" – davidgo Nov 07 '14 at 05:31
  • possible duplicate of [Routing based on the source ip](http://serverfault.com/questions/288333/routing-based-on-the-source-ip) – davidgo Nov 07 '14 at 05:33
  • Apologies for confusing you. I am not looking for source based routing. I am looking for all packets hitting a specific route to use a specific source ip instead of the outgoing interface IP. Is it possible to do that using src option in "ip route". I am not able to use eth1.100s ip on packets going out on tsgw. – wolverine Nov 07 '14 at 06:46

1 Answers1

0

I would use iptables to accomplish that.

With masquerading it would look like:

iptables -t nat -A POSTROUTING -o tsgw -j MASQUERADE
Mathias Weidner
  • 417
  • 3
  • 10
  • Thanks. I was thinking source option in ip route add would solve this problem for me but it doesnt seem to be the case. I couldnt find enough documentation on what cases the source IP setting works and doesnt work. – wolverine Nov 07 '14 at 18:38