How to add routing in linux

藏色散人
Release: 2020-05-24 11:31:11
Original
6053 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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 (永久开启)
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template