Linux adds static routing table, restart continues to work

Source: Internet
Author: User

In daily use. either server on. There are two addresses, two network card configuration, access to different network segments. Such a situation is a very common phenomenon. However, we need to add an extra to the routing table to determine which packets are sent through the correct gateway, and interface can communicate properly today to introduce you to the Linux operating system how to add routes (for Rhel series, test Platform for rhel5.4)
First, use the route command to join a route added to the host temporarily route # route Add-host 192.168.1.123 Dev eth0# routeAdd-host 192.168.1.123 gw192.168.1.1 joins the route to the network # route add-net 192.168.1.123 netmask 255.255.255.0eth0# Route add-net 192. 168.1.123 netmask 255.255.255.0 gw192.168.1.1# Route add-net 192.168.1.123 netmask 255.255.255.0 gw192.168.1.1 eth1# rout E add-net 192.168.1.0/24 eth1 Add default gateway # route add defaults GW 192.168.1.1 Remove route # route Del-host 192.168.1.11 Dev eth0# Route D El-net 192.168.1.123 netmask 255.255.255.0
Second, the method of adding permanent route in Linux 1, write/etc/rc.loacl can write the command mentioned above/etc/ Rc.local file, so that when the system starts, it will actively increase the relevant routing settings on its own, there is a drawback: Suppose that a system service, say, an NFS service, after starting the network service, before running rc.local, assume that you set the NFS to be mounted on its own initiative. Well, the link here is not smooth. Will cause a mount failure. The other is that if you restart the network server, then the route is invalidated, and you have to load the file again, but suppose you are remotely operating? So, this method is not very recommended2, in the/etc/sysconfig/network to add to the end of the file, the format such as the following (note: not verified validity): Gateway=gw-ip or Gateway=gw-dev such a way from the appearance can only be used to join the default gateway.

。 For the multi-channel network environment seems to be not suitable for the look3. Write directly to the Ifcfg file when configuring the IP address to write the gateway configuration directly to the Ifcfg file. Form: Gateway=gw-ip suitable for joining the default route4, write/etc/sysconfig/static-routes file by default in the/ETC/SYSCONIFG folder is not this file, we need to create manually. The call to this file is in the following:/etc/init.d/network:159# ADD noninterface-specific static-routes.160if [-f/etc/sysconfig/static-routes]; Then161grep "^any"/etc/sysconfig/static-routes | While read ignore args; Do162 /sbin/route add-$args163Done164Fi/etc/sysconfig/static-routes:Any net 192.168.1.0/24 GW 192.168.1.24any net 192.168.2.0 netmask 255.255.255.0 GW 192.168.2.1 in a way that is more useful than rc.local. Also, for example, NFS, the effective time of this route is in effect when the network service is started, while some other network related services are started after the successful start of network service, so the network link can be ensured smoothly. And, suppose I restart the Network service, this script is called by the script inside the network service startup. As a result, it also increases its own initiative on the relevant route

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Linux adds static routing table, restart continues to work

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.