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

The method of adding routing in linux system

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article will explain in detail the method of adding routing in the linux system. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

One: use the route command to add (temporary routing)

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

/ / routes added to the host # route add-host 192.168.168.110 dev eth0# route add-host 192.168.168.119 gw 192.168.168.1Accord / routes added to the network # route add-net IP netmask MASK eth0# route add-net IP netmask MASK gw IP# route add-net IP/24 eth2// add default gateway # route add default gw IP// delete route # route del-host 192.168.168.110 dev eth0

Free video tutorial recommended: linux video tutorial

Second: the method of setting permanent route under linux:

1. Add to / etc/rc.local

Methods:

Route add-net 192.168.3.0 gw 24 dev eth0 route add-net 192.168.2.0 24 gw 192.168.2.254 route add-net 180.200.0.0 netmask 255.255.0.0 gw 10.200.6.201 dev eth0 metric 1

Parameter description:

Route add: command keyword to add a route, or route del to delete a route

-host/-net: indicates whether the routing destination is a host or a network segment

Netmask: it is used only when the route destination is a network segment, and indicates the subnet mask of the route destination network segment

Gw: command keyword, followed by next-hop gateway

Dev: command keyword, followed by a specific device name, indicating that the route is going out of that device.

Metric: an integer value (range 1-9999) that specifies the number of hops required for a route, which is used to select the route that best matches the destination address in the forwarding packet among multiple routes in the routing table. The selected route has the least number of hops. The number of hops can reflect the number of hops, path speed, path reliability, path throughput and management attributes.

2. Add to the end in / etc/sysconfig/network

Methods:

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 may cause the NFS not to mount automatically, so it is best to use the static-routes method. Both the restart of the system and service network restart will take effect.

After reading this article, have you learned how to add routing to the linux system? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel. Thank you for reading.

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

Servers

Wechat

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

12
Report