How to show the routing table on Linux with the bash command shell.

The netstat command may be used to show the routing tables for your network connection easily. Use the netstat -r command to achieve this.

iMac05:~ admin$ netstat -r
Routing tables
Destination        Gateway            Flags        Refs      Use   Netif Expire
default          UGSc           31        0     en0
127                localhost          UCS             0        0     lo0
localhost          localhost          UH              0        0     lo0
169.254            link#4             UCS             0        0     en0
172.18.31/24       link#4             UCS            15        0     en0        0:26:f1:f5:3:0     UHLWIir        32        0     en0   1190
pdc.waggit.local   2:22:19:b1:a1:8c   UHLWIi          4       70     en0   1194
gen12.waggit.local localhost          UHS             0        0     lo0
d2-13-b-2-66b.wagg 0:24:1d:c:8f:71    UHLWIi          0        2     en0   1065       3c:7:54:5b:b7:85   UHLWIi          0        0     en0   1168
gen01.waggit.local 0:1e:37:47:c6:e2   UHLWIi          0        0     en0   1162       link#4             UHLWIi          0       20     en0       0:1e:37:47:c6:6a   UHLWIi          0        7     en0   1171
d2-13-b-2-27a-8.wa 0:24:1d:c:8f:bd    UHLWIi          0        3     en0   1167
gen05.waggit.local 0:1e:37:47:c1:72   UHLWIi          1       33     en0   1174       0:1e:37:47:c6:1e   UHLWIi          0        7     en0   1171       link#4             UHRLWIi         2       18     en0
gen14.waggit.local d0:50:99:d:aa:ea   UHLWIi          0        7     en0   1194      ff:ff:ff:ff:ff:ff  UHLWbI          0       86     en0
Destination        Gateway            Flags         Netif Expire
localhost          link#1             UHL             lo0
fe80::%lo0         localhost          UcI             lo0
localhost          link#1             UHLI            lo0
fe80::%en0         link#4             UCI             en0
imac05.local       0:1f:f3:55:92:fa   UHLI            lo0
admins-imac-288.lo 3c:7:54:5b:b6:b0   UHLWIi          en0
admins-imac-163.lo 3c:7:54:5b:be:78   UHLWIi          en0
share-imac.local   3c:7:54:5c:62:9b   UHLWIi          en0
fe80::%en1         link#5             UCI             en1
ff01::%lo0         localhost          UmCI            lo0
ff01::%en0         link#4             UmCI            en0
ff01::%en1         link#5             UmCI            en1
ff02::%lo0         localhost          UmCI            lo0
ff02::%en0         link#4             UmCI            en0
ff02::fb%en0       link#4             UHmW3I          en0   1663
ff02::%en1         link#5             UmCI            en1

This command shows the proper routing table for your UNIX or Linux machine.

A way to show all listening ports on your machine is this command. lsof -n -i | awk '{ print $1,$9; }' | sort -u. This will allow you to see everything that has a listening port on a UNIX system.

iMac05:~ admin$ lsof -n -i | awk '{ print $1,$9; }' | sort -u
NetworkBr *:*
SystemUIS *:*

This is how to get the default gateway on a UNIX system.

iMac05:~ admin$ route -n get default
   route to: default
destination: default
       mask: default
  interface: en0
 recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
       0         0         0         0         0         0      1500         0

This is one other way to do this, this command will show the default gateway.

iMac05:~ admin$ netstat -rn | grep default
default          UGSc           36        3     en0

These networking commands will be very useful to someone that is working with networked machines and they need information about the network layout on their site.

No comments have been made. Use this form to start the conversation :)

Leave a Reply