Home >Operation and Maintenance >Linux Operation and Maintenance >How to add routing in linux system

How to add routing in linux system

王林
王林Original
2019-12-13 17:55:3331298browse

How to add routing in linux system

1: Use the route command to add (temporary route)

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

//添加到主机的路由
# route add –host 192.168.168.110 dev eth0
# route add –host 192.168.168.119 gw 192.168.168.1
//添加到网络的路由
# route add –net IP netmask MASK eth0
# route add –net IP netmask MASK gw IP
# route add –net IP/24 eth1
//添加默认网关
# route add default gw IP
//删除路由
# route del –host 192.168.168.110 dev eth0

Free video tutorial recommendation: linux video tutorial

2: How to set up permanent routing under Linux:

1. In /etc/rc. Add

method in local:

route add -net 192.168.3.0/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, indicating to add a route. To delete a route, use route del;

-host/-net: Indicates whether the routing target is a host or a network segment;

netmask: It is used when the routing target is a network segment, indicating the subnet mask of the routing target network segment;

gw: Command keyword, followed by the next hop gateway;

dev: Command keyword, followed by the specific device name, indicating that the route is sent from the device.

metric: Specifies the integer value of the required hop count for the route (range is 1 ~ 9999). It is used to select the route that best matches the destination address in the forwarded packet among multiple routes in the routing table. . The selected route has the lowest number of hops. Hop count reflects the number of hops, path speed, path reliability, path throughput, and management attributes.

2. Add to the end of /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

If you add routes in rc.local, it may cause NFS to be unable to automatically mount, so it is best to use the static-routes method. It will take effect regardless of restarting the system and service network restart.

Recommended related articles and tutorials: linux tutorial

The above is the detailed content of How to add routing in linux system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn