Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

(transfer) CentOS add permanent static rout

2025-03-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Original: http://blog.chinaunix.net/u/504/showart_2181493.html

When using dual network cards and two gateways at the same time, you need to add a static route. Of course, there are many times when it needs to be routed.

One: use the route command to add

The route added using the route command becomes invalid after the machine is rebooted or the network card is restarted. Method:

/ / routes added to the host

# route add-host 192.168.1.11 dev eth0

# route add-host 192.168.1.12 gw 192.168.1.1

/ / routes added to the network

# route add-net 192.168.1.11 netmask 255.255.255.0 eth0

# route add-net 192.168.1.11 netmask 255.255.255.0 gw 192.168.1.1

# route add-net 192.168.1.0 take 24 eth2

/ / add a default gateway

# route add default gw 192.168.2.1

/ / Delete a route

# route del-host 192.168.1.11 dev eth0

Second: the method of setting permanent route under linux:

1. Add to / etc/rc.local

Methods:

Route add-net 192.168.3.0 ax 24 dev eth0

Route add-net 192.168.2.0ax 24 gw 192.168.2.254

two。 Add to the end in / etc/sysconfig/network

Method: GATEWAY=gw-ip or GATEWAY=gw-dev

3./etc/sysconfig/static-routes:

Any net 192.168.3.0/24 gw 192.168.3.254

Any net 10.250.228.128 netmask 255.255.255.192 gw 10.250.228.129

Adding routes to rc.local will cause the NFS not to mount automatically, so the method of using static-routes is the best. Both restart the system and service network restart will take effect.

The following is a description of mosquitoes solving NFS problems:

According to the order in which the linux starts, the contents of the rc.local are executed only after all the services of the linux are started, that is to say, the contents are executed after the netfs, that is, when the netfs starts, the static routes on the server are 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 is executed. The file is placed in the / etc/sysconfig directory, and the location in the network script is:

# 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

As you can see from this script, this is the way to add static routes. Static-routes is written as

Any net 192.168.0.0 any net 16 gw Gateway ip

In this way, the route is automatically added when the network script is started, and because the network is started in front of the netfs, it naturally works when the nfs is mounted.

From this point of view, if you need to add a static route, using a static-routes file is better than using rc.local, and when you change the network configuration and need to restart the network script, the corresponding static route can be added automatically, but if you use rc.local, the static route that was added will disappear when the network service is restarted.

[@ more@]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report