linux - How do I route a packet to use localhost as a gateway? -
i'm trying test gateway wrote(see what's easiest way test gateway? context). due issue i'd rather not into, gateway , "sender" have on same machine. have receiver(let's 9.9.9.9) gateway able reach.
so i'll run application ./sendstuff 9.9.9.9
send packets ip address.
the problem is: how packets destined 9.9.9.9 go gateway on localhost? i've tried:
sudo route add -host 9.9.9.9 gw 127.0.0.1 lo
sudo route add -host 9.9.9.9 gw <machine's external ip address> eth0
but neither of pass packets through gateway. i've verified correct ips present in sudo route
. can do?
per request, here route table, after running second command(ip addresses changed match question. x.y.z.t ip of machine i'm running on):
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 <gateway addr> 0.0.0.0 ug 100 0 0 eth0
127.0.0.1 picking packets, forwarding them on merry way if ipv4 packet forwarding enabled. if it's not enabled, drop them.
if trying forward packets destined 9.9.9.9 127.0.0.1, iptables.
edit: try this:
iptables -t nat -a output -d 9.9.9.9 -j dnat --to-destination 127.0.0.1
that should redirect traffic 9.9.9.9 localhost instead.
Comments
Post a Comment