Linux Static routing configuration

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.