Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Ubuntu box server has 2 network interfaces:


Ubuntu box client has 1 network interface:


server and client can already talk to each other just fine. Here is client's routing table: via dev eth0 dev eth0  proto kernel  scope link  src via 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

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

route add dev eth0

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

# route add default gw
SIOCADDRT: No such process
share|improve this question
Could you add output of the "# traceroute" executed from the client to the question? – ALex_hha Feb 21 '14 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 '14 at 23:17

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

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

share|improve this answer
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? – MrSilver AG Feb 21 '14 at 17:11
Not impossible, just extremely difficult. A VPN or some other tunneling protocol would help a lot. – NickW Feb 21 '14 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 – Enno Gröper Feb 21 '14 at 22:07

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
share|improve this answer
Installing OpenVPN is way overkill to solve a routing problem. – Andrew Schulman Feb 23 '14 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). – Enno Gröper Feb 23 '14 at 16:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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