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

I'm not the System Administrator of our corporate network, but I've got two Linux workstations (hosts A and B) with root access to both.

Both hosts can see each other fine (ssh, ping, etc works from one to the other). However, only host A can reach out of our corporate firewall and access the Internet etc; host B cannot.

Question: How could I have all (and not just HTTP) outgoing and incoming network traffic at host B routed via host A, without involving my System Administrator? Right now, I don't know if I would need to use NAT for host B, and/or make host A a proxy server, and/or make host A a router.

On Host B, I tried issuing a route add -host <HostA> gw <HostA's Gateway> command, but it didn't work: I was unable to ping from Host B. Please pardon my ignorance on this subject of routing/networking.

share|improve this question
up vote 6 down vote accepted

You have multiple solutions to do this :

Easier way : NAT

Make A a router by allowing forwarding : sysctl net.ipv4.ip_forward=1 Put net.ipv4.ip_forward=1 in /etc/sysctl.conf to make it permanent.

Then on A, nat trafic by typing : iptables -t nat -A POSTROUTING -o ethx -j MASQUERADE

Finally on B : Route all traffic via A :

ip route del default  
ip route add default via IP_of_A

Other solution : Proxify,

but you need to setup all the components to use the proxy:

On B, open an SSH connection to A with this command :

ssh -D8000 -N -f user@IP_of_A 

This will open a proxy sock on B and relay all traffic via A. If you use a web browser for example, you'll need to setup a proxy sock v5 on listening on port 8000. You will not need to setup ip forwarding or touching to routes.

share|improve this answer
On issuing the ip route add command, I got this error: Error: either "to" is duplicate, or "gw" is a garbage. – Harry Aug 29 '11 at 11:53
Btw, DrGkill, I would greatly, GREATLY appreciate if you could also mention the other ways. And also, some book/resource where these concepts are covered in a practical way. I don't need Tannenbaum-like theory, rather concepts and actual Linux commands I can try out and learn would be helpful. Not sure, if the apparently dated [](Linux Network Administrator's Guide) is still current and covers the recipe you gave above. Thanks much and God bless. – Harry Aug 29 '11 at 12:04
The correct syntax is ip route add default via or route add default gw. – quanta Aug 29 '11 at 13:07
Mistake edited, plus the proxy way added. Enjoy. – DrGkill Aug 29 '11 at 15:20
Thanks quanta! The command was accepted successfully. But, when I now ping, I get a From hostA (<ipaddrOfHostA>) icmp_seq=1 Destination Host Prohibited error, and 100% packet loss. – Harry Aug 29 '11 at 15:30

I believe you will need to disable your firewall.

service iptables stop

Not sure if that is necessary on both Host A & Host B, but it did get me passed the "Destination Host Prohibited" message

share|improve this answer

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.