By Manny Fernandez

October 19, 2019

Adding Static Routes on Different OS’s

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

VRF Explained: Virtual Routing and Forwarding on FortiGate, Cisco and Juniper

VRF Explained: Virtual Routing and Forwarding on FortiGate, Cisco and Juniper

Learn virtual routing and forwarding (VRF), then build VRFs and route leaking on FortiGate, Cisco IOS XE and Juniper Junos with tested CLI.

Read More
The /31 Subnet: Myth or Standard? Network and Broadcast Addresses on Point-to-Point Links

The /31 Subnet: Myth or Standard? Network and Broadcast Addresses on Point-to-Point Links

Is the /31 subnet a myth? Learn how RFC 3021 drops the network and broadcast address, when to use /31 links, and when not...

Read More
FortiGate BFD: What It Is, When to Use It, and How to Configure It

FortiGate BFD: What It Is, When to Use It, and How to Configure It

Configure BFD on FortiGate to cut routing failure detection to under one second. Includes CLI steps for BGP, OSPF, and static route protection.

Read More