-1

i would like to replicate what openvpn redirect-gateway does, routing all traffic over a internet server into the internet and back. my client pc -> home router -> internet -> 1.2.3.4 -> internet

this is my normal "route -n" output with a working internet connection:

0.0.0.0         0.0.0.0         0.0.0.0         U     0      0        0 ppp0
mydslip         0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

now i would like to send all traffic over 1.2.3.4, so not directly into the internet, but with a router in between.

what i tried:
route add default 1.2.3.4

which results in:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         1.2.3.4         0.0.0.0         UG    0      0        0 ppp0
0.0.0.0         0.0.0.0         0.0.0.0         U     0      0        0 ppp0
mydslip         0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

this does not redirect the traffic as i would like, its still going straight into the internet and not over 1.2.3.4 so i tried (from the first routing table above):

route del default gw 0.0.0.0

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
mydslip         0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

but now adding:
route add default 1.2.3.4

results in:

SIOCADDRT: Network is unreachable

which makes sense since the default route is gone...how to add it?
the entry with 0.0.0.0 in the first 3 columns doesnt make sense to me:

0.0.0.0         0.0.0.0         0.0.0.0         U     0      0        0 ppp0

how does that allow traffic to go anywhere?

i also tried this:

0.0.0.0         1.2.3.4         0.0.0.0         UG    0      0        0 ppp0
mydslip         0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
1.2.3.4         mydslip         255.255.255.255 UGH   0      0        0 ppp0
1.2.3.4         0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

which does not work, packets go straight into the internet

0

Your approach won't work because the way IP routing works in general. Explaining IP routing here is not suitable for a Q&A site like Serverfault, it would take far too much text.

The way to make it happen is like this:

  1. Create a tunnel for IP packets between source and your desired router.
  2. Ensure that your routing table contains a valid route to your router (The public IP address of the router via a working gateway).
  3. Replace the default route with the tunnel IP address of the router at the source computer.

You also need to make sure that this other router has proper configuration to route the packets from/to the tunnel.

  • maybe you know the name of a book or a link to a site that would help? – Julius Junghans Mar 7 '17 at 18:26
  • Googling for "IP routing" gives several resources on the subject. I read "Internetworking with TCP/IP Volume 1" book back in the days. – Tero Kilkanen Mar 7 '17 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.