How does the CentOS server add permanent static routes?

Source: Internet
Author: User
Tags centos centos server

How does the CentOS server add permanent static routes?

One, Linux add permanent static route

Method One: Modify the rc.local configuration file

Scope: Test Ubuntu 14.04, CentOS 6.4, Debian 8.1, Redhat 6.4 system available

How to use:

1. Add a command to the/etc/rc.local file in the Linux system Route add-net 192.168.2.0/24 GW 192.168.2.254 (the default route for the server is 192.168.2.254), or add a command route Add-net 192.168.3.0/24 Dev Eth0, the former relies on the default route for data forwarding, which relies on the NIC interface for data forwarding

2.reboot Reboot system command takes effect

3. Use the Route-n command to see if the command has taken effect

Method Two: Modify the static-routes configuration file

Scope: Test CentOS 6.4, Redhat 6.4 system available

Use method (This method is more practical than rc.local method, can ensure the smooth network link):

1. Add commands to the system's/etc/sysconfig/static-routes file (if the system does not have this file to create a new file) any net 192.168.2.0 netmask 255.255.255.0 GW 192.168.2.254 (the default route for the server is 192.168.2.254), or add the command any net 192.168.2.0 netmask 255.255.255.0 dev eth0, which relies on the default route for data forwarding. The latter is dependent on the network card interface for data forwarding

2.service Network Restart command Restart Network Service

3. Use the Route-n command to see if the command has taken effect

Method Three: Modify the interface configuration file

Scope: Test Debian 8.1, Ubuntu 14.04 system available

How to use:

1. Add commands to the system's/etc/network/interface file up route add-net 192.168.2.0/24 GW 192.168.2.254 (the default route for the server is 192.168.2.254), or add a command Up Route add-net 192.168.3.0/24 Dev Eth0, which relies on the default route for data forwarding, which relies on the NIC interface for data forwarding

2.reboot Reboot system command takes effect

3. Use the Route-n command to see if the command has taken effect

* Note 1: (Refer to online content) If you add a route to rc.local, NFS cannot automatically mount the problem, so using Static-routes is the best method. Regardless of the restart System and service network restart will take effect, in the order of Linux boot, the contents of the rc.local inside the Linux all services are started, the last to be executed, that is, this content is in the netfs after the execution, That is to say, the static route on the server is not added when the Netfs is started, so the Netfs mount cannot succeed.

* NOTE 2: The above add command can be added to the second line of the corresponding file via Linux command sed-i ' 2i Route add-net 192.168.2.0/24 GW 192.168.2.254 ' + file path command or with Echo route Add-net 192.168.2.0/24 GW 192.168.2.254 >> file path add command to end of file

Second, Windows add permanent static routes

Method One:

Scope: Test windows2008 system available

How to use:

1. Open Run as Administrator cmd.exe

2. Using the command: route-p add 192.168.2.0 mask 255.255.255.0 192.168.2.1 (the default route for the server is 192.168.2.1)

3. Use route print to see if the command takes effect

Related Article

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.