Home > Article > Operation and Maintenance > How to add routing in linux
How to add routing in Linux?
Methods to add routes under Linux:
1: Use the route command to add routes
Use the route command to add routes, restart the machine or The routing will become invalid after 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
2: Method to set up permanent routing under Linux:
1. Add
## in /etc/rc.local #Method:route add -net 192.168.3.0/24 dev eth0 route add -net 192.168.2.0/24 gw 192.168.3.2542. Add to the end of /etc/sysconfig/network Method: GATEWAY=gw-ip or GATEWAY=gw-dev3. /etc/sysconfig/static-router:
any net x.x.x.x/24 gw y.y.y.ylinux Add permanent static routingLinux routing function: # The route added by the route command will be lost after the machine is restarted or the network card is restarted. How to set a permanent route under Linux: 1. Add in /etc/rc.local 2. Add to the end of /etc/sysconfig/network 3./etc/sysconfig/static-router:
any net x.x.x.x/24 gw y.y.y.y
# echo "1" >/proc/sys/net/ipv4/ip_forward (临时) # vi /etc/sysctl.conf --> net.ipv4.ip_forward=1 (永久开启)Related recommendations: "
The above is the detailed content of How to add routing in linux. For more information, please follow other related articles on the PHP Chinese website!