title: How do I route a packet to use localhost as a gateway?
body: <p>I'm trying to test a gateway I wrote(see <a href="https://stackoverflow.com/questions/4910422/whats-the-easiest-way-to-test-a-gateway">What&#39;s the easiest way to test a gateway?</a> for context). Due to an issue I'd rather not get into, the gateway and "sender" have to be on the same machine. I have a receiver(let's say 9.9.9.9) which the gateway is able to reach.</p>
  
  <p>So I'll run an application <code>./sendStuff 9.9.9.9</code> which will send some packets to that IP address.</p>
  
  <p>The problem is: how do I get the packets destined for 9.9.9.9 to go to the gateway on localhost? I've tried:</p>
  
  <p><code>sudo route add -host 9.9.9.9 gw 127.0.0.1 lo</code></p>
  
  <p><code>sudo route add -host 9.9.9.9 gw &lt;machine's external IP address&gt; eth0</code></p>
  
  <p>but neither of those pass packets through the gateway. I've verified that the correct IPs are present in <code>sudo route</code>. What can I do?</p>
  
  <hr>
  
  <p>Per request, here is the route table, after running the second command(IP addresses changed to match the question. x.y.z.t is the IP of the machine I'm running this on):</p>
  
  <pre><code>Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
  9.9.9.9         x.y.z.t         255.255.255.255 UGH   0      0        0 eth0
  x.y.z.0         0.0.0.0         255.255.254.0   U     0      0        0 eth0
  0.0.0.0         &lt;gateway addr&gt;  0.0.0.0         UG    100    0        0 eth0
  </code></pre>