Loading

In this short blog, we will take a look at how to add a static route to our Ubuntu/ MAC / Windows OS

Command in MAC

route -n add -net 172.16.11.0/24 192.168.1.25

where 192.168.1.25 is the router IP and 172.16.11.0/24 will be our subnet

Show Routes

To show learned routes on a Mac, run the command

netstat -rn 

where -r flag shows routes and -n flag means not to resolve the hostname to IP resolution

netstat -rn

As seen our default gateway of this Mac is 192.168.1.1.

Command in Ubuntu

sudo ip route add 172.16.11.0/24 via 192.168.1.25 dev wlp2s0 

where 172.16.11.0/24 is the subnet range, 192.168.1.25 will be our router, and w1ps2o will be the ethernet interface on the ubuntu

Show Routes

To show learned routes on a Ubuntu, run the command

netstat -rn 

where -r flag shows routes and -n flag means not to resolve the hostname to IP resolution

netstat -rn

Command in Windows

route -p add 172.16.11.0  mask 255.255.255.0 192.168.1.25 

where -p will indicate that our static route will be persistent with system reboots

To show learned routes on Windows OS, run the command

netstat -rn 

(Visited 618 times, 1 visits today)

By C A Thomas

Chinchu A. Thomas is an Infrastructure Analyst specializing in Microsoft Azure, the Microsoft 365 suite, AWS, and Windows infrastructure management products.

Leave a Reply