2

Ubuntu box server has 2 network interfaces:

eth0 50.57.71.100
eth1 10.182.161.100

Ubuntu box client has 1 network interface:

eth0 10.177.30.100

server and client can already talk to each other just fine. Here is client's routing table:

10.176.0.0/12 via 10.177.0.1 dev eth0 
10.177.0.0/17 dev eth0  proto kernel  scope link  src 10.177.30.100
10.208.0.0/12 via 10.177.0.1 dev eth0 

I have enabled ipv4 forwarding on server's kernel. How can I set this up so any internet traffic from machine client gets routed through server? (like say, ping 8.8.8.8)

I tried adding a route on client but lost all network connectivity until I deleted it:

route add 10.182.161.100/32 dev eth0

I tried setting a client's default gateway to server but this fails:

# route add default gw 10.182.161.100
SIOCADDRT: No such process
2
  • Could you add output of the "# traceroute 10.182.161.100" executed from the client to the question?
    – ALex_hha
    Feb 21, 2014 at 22:44
  • please add the output of ip route list for both server and client, this is just too confusing otherwise. You will need to enabled ip forwarding on the server for it to be able to route the clients traffic and most likely also MASQUERADE it via netfilter because generally RFC1918 networks like the 10.x.x.x ones you are using internally are not being routed in the internet.
    – ZaphodB
    Feb 21, 2014 at 23:17

2 Answers 2

1

If you want traffic from a network behind router 10.177.0.1 to go out through a different route (to server specifically), set the route up in 10.177.0.1 pointing to server.

This would direct all outgoing traffic that passes through 10.177.0.1 through server, and I am not sure that is what you want.

3
  • thanks, is this the only way? what if I only have access to 'client' and 'server' and lack access to any routers in between. Does this make my scenario impossible? Or maybe its doable with a VPN of some sort? Feb 21, 2014 at 17:11
  • 3
    Not impossible, just extremely difficult. A VPN or some other tunneling protocol would help a lot.
    – NickW
    Feb 21, 2014 at 17:20
  • If the router supports policy based routing, you could define a route based on the source address. But without using some kind of tunnel, you can't achieve what you want without control of all routers in between Feb 21, 2014 at 22:07
0

You could install an OpenVPN server on your server and a client on your client. Using "redirect-gateway def1" the default route of your client is redirected to your server.
After you have a working OpenVPN setup, you have to deploy NAT (masquerading) to get rid of the clients private ip on the internet side.

UPDATE: After Andrew Schulmans comment I researched a bit further. Because your goal is not security of the tunnel, a GRE tunnel will suit your needs better and is easier to setup. In your case the default route of the client needs to point to the server and you have to do masquerading:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

To make iptables rules persistent:

service iptables save
2
  • Installing OpenVPN is way overkill to solve a routing problem. Feb 23, 2014 at 10:45
  • Without control of the routers in between, this is a tunneling problem. Of course there could be an easier way to setup a tunnel for general use (tunnel all traffic from client to server). Feb 23, 2014 at 16:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .