Home  >  Article  >  Operation and Maintenance  >  How to add routing in linux

How to add routing in linux

藏色散人
藏色散人Original
2020-05-24 11:31:115989browse

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.254

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

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

3. /etc/sysconfig/static-router:

any net x.x.x.x/24 gw y.y.y.y

linux Add permanent static routing

Linux 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

Enable IP forwarding:

# echo "1" >/proc/sys/net/ipv4/ip_forward (临时)
# vi /etc/sysctl.conf --> net.ipv4.ip_forward=1 (永久开启)

Related recommendations: "

linux tutorial"

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!

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