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.
Asked
Active
Viewed 1,558 times
0

user2284355
- 455
- 2
- 10
- 24
-
none of those work im asking the same question here https://unix.stackexchange.com/questions/614201/linux-add-static-route-simple-works-on-windows-not-on-linux – user3265051 Oct 12 '20 at 22:18
2 Answers
4
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>

Pascal Schmiel
- 1,738
- 12
- 17
-
route add -net 192.168.3.0 netmask 255.255.255.0 gw
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 08 '13 at 12:22 -
1You 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 08 '13 at 12:39
1
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.

Robbie Mckennie
- 1,123
- 1
- 8
- 21