Skip to content
Advertisement

Linux – Route Specific Traffic Through Ethernet

At work we have 2 networks; a WiFi one for normal Internet access, and an internal LAN one, for the repo etc. I’ve recently started using Linux and it’s a pain having to constantly switch between cable and WiFi. On Windows, we solved it (so that we can be connected to both network simultaneously) by running the commands:

# Add a route for all traffic to any destination starting with 10 (internal traffic):
route add 10.0.0.0 mask 255.0.0.0 10.18.21.129 metric 40 -p
# Move the default route to a higher metric:
route change 0.0.0.0 mask 0.0.0.0 10.18.21.129 metric 40

After running these and connecting to WiFi, everything worked magically. What would the necessary Linux commands be to achieve the same result? I’ve fiddled around a lot with the route command, but haven’t had any luck. Appreciate any help.

EDIT: Here is the output of the route -n command before entering any other commands:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.18.21.129    0.0.0.0         UG    0      0        0 eth0
10.18.21.128    0.0.0.0         255.255.255.128 U     1      0        0 eth0
192.168.56.0    0.0.0.0         255.255.255.0   U     0      0        0 vboxnet0
192.168.88.0    0.0.0.0         255.255.252.0   U     9      0        0 wlan0

Advertisement

Answer

Variant 1: Direct translation of your solution to linux one

route command:

  • route add -net 10.0.0.0/8 gw 10.18.21.125 metric 40
  • route del default
  • route add default gw 10.18.21.125 metric 40

ip route command:

  • ip route add 10.0.0.0/8 via 10.18.21.125 metric 40
  • ip route del default via 10.18.21.125
  • ip route add default via 10.18.21.125 metric 40

add launch of these command after wifi would be connected or to startup script.

Variant 2. Turn magic off 🙂

  • turn route of 10.0.0.0 network via your LAN interface using command like this: ip route add 10.0.0.0/8 via 10.18.21.125 metric 10. In that case all traffic would be routed via default interface, except 10.0.0.0/8 network.
  • increase priority for default wifi route, if he is lower than LAN one

PS. Possibly this question should be placed on Server Fault site 🙂

EDIT: according to provided route map

  • route del default
  • route add default gw [wifi gateway ip]
  • route add -net 10.0.0.0/8 gw 10.18.21.125
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement