Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.


I have a Linux box with two interfaces.
eth0 has ip 192.168.71.82/255.255.252.0
eth1 has ip 192.168.4.2/255.255.255.0
I need all traffic for subnets 192.168.4.0/24 192.168.3.0/24 192.168.2.0/24 to go through eth1 and all the rest to go through eth0.
Which is the best way to do this?
route command?
Cheers for the help.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Just set routes to your desired Networks over eth1:

route add -net 192.168.4.0 netmask 255.255.255.0 dev eth1
route add -net .........

And then set your default gateway to whatever you need:

route add default dev eth0

(Nevertheless a route using an interface looks a bit strange to me - usually you should address the gateways using the correct router(s):

route add -net 192.168.3.0 netmask 255.255.255.0 gw <your routers IP>
share|improve this answer
    
route add -net 192.168.3.0 netmask 255.255.255.0 gw <your routers IP> worked like a charm. Cheers for the help. How would I go about making the changes stick after reboot on a Debian based distro? –  user2284355 Jul 8 '13 at 12:22
1  
You can add commands in /etc/network/interfaces that should be executed after the interface is up using the keyowrkd "up" in your interface section. F.e.: "up route add -net ......." –  Pascal Schmiel Jul 8 '13 at 12:39
add comment
route add default gw <eth0 gateway> dev eth0
route add 192.168.4.0 netmask 255.255.255.0 gw <eth1 gateway> dev eth1
route add 192.168.3.0 netmask 255.255.255.0 gw <eth1 gateway> dev eth1
route add 192.168.2.0 netmask 255.255.255.0 gw <eth1 gateway> dev eth1

That ought to do it.

share|improve this answer
add comment

Your Answer

 
discard

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.