Get the App
SLTechnology News&Howtos  ›  Servers  › 

The method of adding routing in linux system

Shulou Source: shulou.com Published: 2022-06-03 02:41:02 10月27日 Update

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.

Tags: Routes methods commands targets systems keys keywords points articles network segments paths hosts tutorials more gateways video devices utility content parameters Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Huawei MariaDB vpn OPPO Reno