I have a bunch of routes to my LAN line that won't resolve through my WiFi (which is set as 1st order).

sudo route add 10.999.999.999 10.888.888.888

I have a lot more but that's just a sample. This works great but sometimes I need access to another Network asset which means I have to go add it to the list again.

Can I make it so I route any IP address starting with 10 gets rerouted through the LAN router?

Something like this:

sudo route add 10.* 10.888.888.888


My Setup:

I have two internet connections.

  1. WiFi - no firewalls - no access to network assets
  2. LAN - firewalls - access to network assets

I set WiFi first in my order of precedence and I force certain domains through the LAN connection using my host file to resolve the IP addresses and a routes table to direct those IPs through my LAN router.

Basically I want my cake and eat it too.

Here is what I ended up with:

#! /bin/bash    
sudo route -n flush
sudo route add -net 10    
networksetup -setairportpower en0 off    
sleep 2    
networksetup -setairportpower en0 on

This flushes the route table, routes any traffic starting with the ip address 10. to my LAN connection's router, then restarts the wifi router (en0).

  • 1
    the three digit numbers in an IPv4 address only go to 255 not 999. 10.999.999.999 isn't a valid IP address.
    – sdmeyers
    Oct 10 '14 at 14:54
  • Thanks. I didn't feel right putting in my IP addresses. I suppose I could have commented that these were just placeholder IP addresses but I assumed that was obvious. Oct 10 '14 at 15:00
  • 1
    How about bash expansion? You can write something like: 10.{0..255}.{0..255}.{0..255} It'll expand to all IPs beginning with number 10. Oct 10 '14 at 15:01
  • @MateuszSzlosek Testing now! Oct 10 '14 at 15:01
  • @MateuszSzlosek 'Argument list too long' Oct 10 '14 at 15:03

The correct form to add a net route is

route add -net 10 $GW

Obviously you have to replace $GW with the ip address of your gateway.

  • Dang that makes way more sense. Thanks for your patience . Obviously I don't know bash scripts at all. Oct 10 '14 at 19:07

You can use for loops. Here's an example:

for i in {0..255}; do
    for j in {0..255}; do
        for k in {0..255}; do
            sudo route add 10.$i.$j.$k 10.888.888.888
  • Isn't this the same as your expansion comment? Oct 10 '14 at 15:14
  • No It's not, because right now route command is run separately for every IP address. Oct 10 '14 at 15:16
  • 1
    I guess this answers the question, but 16 million iterations seems a bit overkill. If I were the asker, I'd go about this another way.
    – jonescb
    Oct 10 '14 at 15:28
  • @jonescb Exactly. Had to stop it a t *.*.4.255 Oct 10 '14 at 15:29
  • please don't do that
    – user94148
    Oct 10 '14 at 17:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .