Add static routes to Linux

Source: Internet
Author: User

1. Use the route command to view the native route and enter the route return directly.
Route command
Parameters:

    1. Add Add route
    2. del Delete route
    3. -net setting a route to a network segment
    4. -host setting a route to a host
    5. GW Export Gateway IP address
    6. Dev Egress Gateway Physical device name



Example

    1. Add route
    2. Route add-net 192.168.0.0/24 GW 192.168.0.1
    3. Route Add-host 192.168.1.1 Dev 192.168.0.1
    4. Delete route
    5. Route del-net 192.168.0.0/24 GW 192.168.0.1
    6. Add a default route
    7. Route add default GW 192.168.0.1



2. Using the IP route command is similar to the route command
Parameters:

    1. Add Add route
    2. del Delete route
    3. Via Gateway egress IP Address
    4. Dev Gateway Export Physical device name


Example

    1. Add route
    2. IP route add 192.168.0.0/24 via 192.168.0.1
    3. IP route add 192.168.1.1 dev 192.168.0.1
    4. Delete route
    5. IP route del 192.168.0.0/24 via 192.168.0.1
    6. Add default route
    7. IP route add default via 192.168.0.1 dev eth0


The static route restarts that are added by both methods disappear, and the following method adds a permanent route.
1.
Create a file named Route-eth0 under the/etc/sysconfig/network-script/directory
Vi/etc/sysconfig/network-script/route-eth0
Add content in this file in the following format
192.168.1.0/24 via 192.168.0.1

Service Network restart
Restart network authentication

2. Add the following in the/etc/sysconfig/static-routes file (create a file manually without static-routes)

    1. Any net 192.168.3.0/24 GW 192.168.3.254
    2. Any net 10.250.228.128 netmask 255.255.255.192 GW 10.250.228.129


It is recommended to use both of these methods, as neither restarting the machine nor restarting the network service route is lost.

3. Add in/etc/rc.local (there will be pits only to restart the server to add this route)
Method:

    1. Route add-net 192.168.3.0/24 Dev eth0
    2. Route add-net 192.168.2.0/24 GW 192.168.2.254

Rc.local is the last script for Linux boot execution, so you can add static routes

Brief description:
If adding a route in rc.local will cause NFS to not mount the problem automatically, according to the Linux boot order, the contents of rc.local in the Linux all services are started, finally executed, that is, the contents of this is netfs after the execution, that is to say, netfs boot , the static route on the server is not added, so the Netfs mount cannot succeed.
What is the Static-routes file, this is a file that is called when the network script executes, and the file is placed in the/etc/sysconfig directory, where it is located in the network script:

Interface Static-routes.   if [-f/etc/sysconfig/static-routes]       ; Then " ^any " /etc/sysconfig/staticwhile do           /sbin/route add-$args        Done     fi  


As you can see from this script, this is the way to add static routes, and Static-routes's notation is
Any net 192.168.0.0/16 GW gateway IP
In this case, the route is added automatically when the network script is started, and because the network is started in front of the netfs, it is naturally normal to mount NFS.

Add static routes to Linux

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.