Jump to content

How to find the Gateway used for Routing


rev.dennis
 Share

Recommended Posts

Probably the easiest command and most popular one is using the ip command.  Example of showing all routes

[root@usdet1lvdwb002 ~]# ip route list
default via 10.6.0.129 dev ens224 proto static metric 100
10.6.0.128/27 dev ens224 proto kernel scope link src 10.6.0.136 metric 100
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
172.18.0.0/16 dev br-d21cec45669b proto kernel scope link src 172.18.0.1

You can use the ip route get <address> command to ask the kernel to report the route it would use to send a packet to the specified address:

[root@usdet1lvdwb002 ~]# ip route get 10.11.24.11
10.11.24.11 via 10.6.0.129 dev ens224 src 10.6.0.136 uid 0
    cache

Another way is running this command

[root@usdet1lvdwb002 ~]# ip route show to match 10.11.24.11
default via 10.6.0.129 dev ens224 proto static metric 100

10.6.0.129 is my default route.

If I ask for an address that would not go over the default route:

[root@usdet1lvdwb002 ~]# ip route get 10.6.0.130
10.6.0.130 dev ens224 src 10.6.0.136 uid 0
    cache

Since the IP is in the same subnet it doesn't need the route IP.

 

I like using tracepath to see how the traffic is going to a certain IP Address.  Below is an example

[root@usdet1lvdwb002 ~]# tracepath 10.44.112.234
 1?: [LOCALHOST]                      pmtu 1500
 1:  _gateway                                             16.178ms
 1:  _gateway                                             15.372ms
 2:  dennis.gearcrushers.com                               0.329ms
 3:  10.10.254.13                                          0.427ms asymm  4
 4:  no reply
 5:  100.65.0.121                                         46.292ms asymm  6
 6:  100.65.0.122                                         36.879ms asymm 11
 7:  ussat1-ccs0001_eth1-57.gearcrushers.com              43.124ms asymm 12
 8:  ussat1-dcs0001_eth1-1_10.gearcrushers.com            45.858ms asymm 12
 9:  gns4.gearcrushers.com                                37.880ms reached
     Resume: pmtu 1500 hops 9 back 12

 

So instead of using the ip command you can use the route command. Using the following command will display the list of routes currently configured

[root@usdet1lvdwb002 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.6.0.129      0.0.0.0         UG    100    0        0 ens224
10.6.0.128      0.0.0.0         255.255.255.224 U     100    0        0 ens224
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
172.18.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-d21cec45669b

 

There are other tools you can use besides route like netstat

This command gives the statistics about the network. With this command you can do more than just printing routing table,

Print network connections

  • routing tables
  • interface statistics
  • masquerade connections
  • multicast memberships

To check the routing table run the following command (-r is to display the routing table and -n is to not resolve the names and just print the IP addresses only)

[root@usdet1lvdwb002 ~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         10.6.0.129      0.0.0.0         UG        0 0          0 ens224
10.6.0.128      0.0.0.0         255.255.255.224 U         0 0          0 ens224
172.17.0.0      0.0.0.0         255.255.0.0     U         0 0          0 docker0
172.18.0.0      0.0.0.0         255.255.0.0     U         0 0          0 br-d21cec45669b

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...