Where is routing table stored internally in the Linux kernel?
The route
or the ip
utility get their information from a pseudo filesystem called procfs
. It is normally mounted under /proc
. There is a file called /proc/net/route
, where you can see the kernel's IP routing table. You can print the routing table with cat
instead, but the route utility formats the output human readable, because the IP adresses are stored in hex.
That file is not just a normal file. It is always generated at exactly the moment when opening it with an attempt to read, as all files in the proc filesystem.
I you are interessted how that file is written, then you need to look at the kernel sources:
That function outputs the routeing table. You see at line 2510, the header of the routing table is printed. The routing table appears to be mostly in the struct fib_info
that is defined in the header file ip_fib.h, line 98.
Related videos on Youtube
syntagma
Updated on September 18, 2022Comments
-
syntagma over 1 year
When I execute
route -n
, from where exactly (from whichstruct
s) is the information displayed retrieved?I tried executing
strace route -n
but I didn't help me finding the right place it's stored.-
Sreeraj about 9 yearsPlease go through this superuser.com/questions/322717/how-does-route-n-work-in-linux
-
Bandrami about 9 yearsIt's stored in memory. Are you looking for the memory address it's at?
-
syntagma about 9 years@Bandrami I would like to see what
struct
is responsible for holding the information. -
David Tonhofer over 5 yearsFor anyone looking for the file on disk, it's either built from whatever the DHCP server gives out, or from what can be found in
/etc/sysconfig/network-scripts/ifcfg-${DEV}
in simple cases and/or from what can be found in/etc/sysconfig/network-scripts/route-${DEV}
in more convoluted cases (case of Red Hat / CentOS 7). The latter file contains the output ofip -r
. See Add a Static Route on CentOS.
-