Analysis of the starting process of Static Routing in CentOS
This article analyzes the Starting Process of Static Routing in RHEL/CentOS, so that students can understand the Starting Process of Linux.
It can help students better understand the Linux system and troubleshoot common errors.
-System Startup Script
/Etc/init. d/network. This script is a bash script, and the key line for static route startup:
action$
"Bringingupinterface$i:"
.
/ifup
$iboot
Ifup refers to/etc/sysconfig/network-scripts/ifup, and $ I refers to interfaces, such as eth0 and bond0.
Boot is actually not needed.
-Open the ifup script. The key two lines are:
OTHERSCRIPT=
"/etc/sysconfig/network-scripts/ifup-${DEVICETYPE}"
exec
${OTHERSCRIPT}${CONFIG}$2
DEVICETYPE is defined in/etc/sysconfig/network-scripts/network-functions. If the DEVICETYPE variable is eth and CONFIG is $1, The executed statement is:
exec
/etc/sysconfig/network-scripts/ifup-eth
$1$2
-Analyze the/etc/sysconfig/network-scripts/ifup-eth script again. The key is the last line:
exec
/etc/sysconfig/network-scripts/ifup-post
${CONFIG}${2}
-Analyze/etc/sysconfig/network-scripts/ifup-post, which contains a line:
/etc/sysconfig/network-scripts/ifup-routes
${REALDEVICE}${DEVNAME}
-Finally, analyze/etc/sysconfig/network-scripts/ifup-routes. This script is used to start Static Routing. There are two functions: handle_file () and handle_ip_file (), both are used to add routes, but the two correspond to the file format that is not used, that is, Static Routing files can have two different formats.
-The following example shows how to automatically Load Static routes at system startup. For example, to add a static route to the bond1 interface, you must first create the file:/etc/sysconfig/network-scripts/route-bond1, then add the following lines to the file (for example ):
10.140.0.0
/15
via10.9.214.1
In another format, the students will study it by themselves and will not repeat it here.