Posted: . At: 3:20 PM. This was 9 years ago. Post ID: 7847
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

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
 
Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            172.18.31.1        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
172.18.31.1        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
172.18.31.40       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
172.18.31.49       link#4             UHLWIi          0       20     en0
172.18.31.53       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
172.18.31.68       0:1e:37:47:c6:1e   UHLWIi          0        7     en0   1171
172.18.31.70       link#4             UHRLWIi         2       18     en0
gen14.waggit.local d0:50:99:d:aa:ea   UHLWIi          0        7     en0   1194
172.18.31.255      ff:ff:ff:ff:ff:ff  UHLWbI          0       86     en0
 
Internet6:
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
COMMAND NAME
NetworkBr *:*
SystemUIS *:*
firefox 172.18.31.29:58612->153.107.103.10:http-alt
firefox 172.18.31.29:58621->153.107.103.10:http-alt
firefox 172.18.31.29:58636->153.107.103.10:http-alt
firefox 172.18.31.29:58637->153.107.103.10:http-alt
firefox 172.18.31.29:58719->153.107.103.10:http-alt
firefox 172.18.31.29:58772->153.107.103.10:http-alt
firefox 172.18.31.29:58774->153.107.103.10:http-alt
firefox 172.18.31.29:58786->153.107.103.10:http-alt
firefox 172.18.31.29:58788->153.107.103.10:http-alt
firefox 172.18.31.29:58789->153.107.103.10:http-alt
firefox 172.18.31.29:58790->153.107.103.10:http-alt
firefox 172.18.31.29:58791->153.107.103.10:http-alt

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
    gateway: 172.18.31.1
  interface: en0
      flags: 
 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            172.18.31.1        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.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.