By Manny Fernandez

October 19, 2019

Adding Static Routes on Different OS’s

Quick post on static routes.  Today I needed to have my MacBook connected to a wired connection after upgrading to Catalina.  On a separate issue, I had to redo all of my mailboxes and download all mail AGAIN, but I digress.  I wanted to have access to my internal network via WiFi while connected to my Gigabit Internet directly via GigE dongle.  I did not remember the syntax for the macOS to add the route.  Here is a quick cheat sheet.

These examples are temporary and once you reboot, they are gone.  The Use Case is to quickly add a route.  In my case, I am adding a route to 10.1.106.0/24 and the next hop for that would be 10.1.105.1

macOS

In macOS, here is the command to add a static route.

sudo route -n add -net 10.1.106.0/24 10.1.105.1

To validate the route in macOS

netstat -r

Linux

sudo route add -net 10.1.106.0/24 gw 10.1.105.1

To validate in Linux

ip route

Windows

route add 10.1.106.0 mask 255.255.255.0 10.1.1.105.1

To validate in Windows

route print

 

I created a route script that can easily be modified for any of the OS’s except Windows.  The script is in Bash

#!/bin/bash
clear
echo "what is the destination network?"
read network
echo "what is the mask?"
read mask
echo "what is the gateway?"
read gateway

route add -net $network netmask $mask gw $gateway

clear

echo "Go get your route on boss"

Yes, I like to have my scripts and MacBook talk to me and boost me ego 🙂

Happy Routing.

Hope this helps

Recent posts

  • There are many options when troubleshooting in FortiGate firewalls. ... Full Story

  • Have you ever had an IPS signature that continues... Full Story

  • Use case:  Customer has a Split Tunnel Enabled but... Full Story