How do you add routes on ubuntu?
Main Topics
Browse All TopicsI have an Ubuntu box with 3 nics in it. 2 of them are bridged for use with Squid. The 3rd nic is on a different network. I only want to use this for SSH into the box. The problem is, all web traffic is going out the 3rd interface. I don't want this to happen. Does anybody know how to accomplish this? I tried removing the default gateway for that interface, and it seemed to work, but then I couldn't SSH into the box anymore. Help!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Please see the link below:
http://www.comptechdoc.org
There will be more than one PC connecting to it from dynamic IPs. Here is a rough Visio drawing that might help: <a href="http://www.tharo.com
I looked at your diagram, and
- your two interfaces that are used for squid are: 192.168.5.1 and 192.168.5.2
- the interface that you are welling to use for ssh is 192.168.4.2 going through FW (is it natted to 1.2.3.174?)
- you have two internet links
- you want to ssh from any where to 3rd interface
It seems that when traffic comes to this interface you do not allow it to go back through 192.168.5.0. Is this correct (since there is no default gateway on the 3rd interface)?
you need to allow this (on your firewall / iptables)
The Squid box does not have any firewall setup on it. eth0 and eth1 are bridged and have an IP of 192.168.5.25. eth2 is 192.168.4.2. I don't want any Internal traffic to go out eth2. It's only for SSH from the outside. If I set a Default GW, ALL internal traffic goes out eth2, even though there is a gateway set for the bridge to 192.168.5.1
You will need to setup policy routing.
Standard Linux has 3 tables local, main, and default.
The trick is to split the 2 default GW's into 2 routing tables and then use routing rules to select the correct one.
see # ip rule show
1. Add normal default route out the bridged interface.
#ip route add default via GWeth1
>>This will end up in main
2. Add default gw out ssh eth2 with
#ip rule add from 192.168.4.2 priority 1000 table 100
then add the default GW
ip route add default via GWeth2 table 100
The rule at 1000 will select the 100 routing table before main if the packet has a source ip of 192.168.4.2
OK, let me make sure I'm clear here before I go messing up my routing tables. I should type the following?
ip route add default via 192.168.5.25 #(This is the IP of the bridge interface. Or should this be the next hop?)
ip rule add from 192.168.4.2 priority 1000 table 100
ip route add default via 192.168.4.2 table 100 #(Again, this is the interface IP, not the gateway IP?)
Thanks a million!
Business Accounts
Answer for Membership
by: omarfaridPosted on 2007-12-21 at 07:32:26ID: 20514179
Can you add static route on the 3rd nic for your ip or subnet? When there was a default gateway on it the server knew how to go back / route to your IP.