After you have configured multiple NICs, you need to specify which NIC the packets are sent from, otherwise you may not be able to access the intranet, which requires static routing.
There are several ways to configure static routes:
1. Modify the/etc/rc.local file so that it will be added automatically after each reboot, such as:
echo "route add default GW 10.0.2.2 dev eth0" >>/etc/rc.local
echo "Route add-net 192.168.100.0 netmask 255.255.255.0 dev eth1" >>/etc/rc.local
This approach has a drawback: static routes fail after you restart the network using service network restart
2, [Recommended] View network startup script:/etc/init.d/network found like the following command:
# Add non interface-specific static-routes. if [-f/etc/sysconfig/static-routes]; then grep " ^any /etc/sysconfig/static-routes | while read ignore args; do /sbin/route Add- $args done fi
If [-f/etc/sysconfig/static-routes],-f means that there is/etc/sysconfig/static-routes and is a normal file, execute the following statement
grep "^any"/etc/sysconfig/static-routes Remove the line that starts with any
While read ignore args executes ignore= "any" args= other
/sbin/route add-$args Add a routed command
Now you can add our own static routes and view the Static-routes format as follows:
Any net 192.168.100.0 netmask 255.255.255.0 Dev eth1
Any net 0.0.0.0 netmask 0.0.0.0 GW 10.0.2.2 Dev eth0
Then restart the network, and the routes are:
[Email protected] ~]# route-nkernel IP Routing tabledestination Gateway genmask Flags Metric Ref use Iface192.168.100.0 0.0.0.0 255.255.255.0U0 0 0eth110.0.2.0 0.0.0.0 255.255.255.0U0 0 0eth0169.254.0.0 0.0.0.0 255.255.0.0U1002 0 0eth0169.254.0.0 0.0.0.0 255.255.0.0U1003 0 0eth10.0.0.0 10.0.2.2 0.0.0.0Ug0 0 0Eth0
Linux Static routing configuration