Linux-Add, modify, delete routes

Source: Internet
Author: User

Show all Routes now
#route
[Email protected] ubuntu:~# Route
Kernel IP Routing Table
Destination Gateway genmask Flags Metric Ref use Iface
10.147.9.0 * 255.255.255.0 U 1 0 0 eth0
192.168.1.0 * 255.255.255.0 U 2 0 0 Wlan0
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
link-local * 255.255.0.0 U 0 0 eth0
192.168.0.0 192.168.1.1 255.255.0.0 UG 0 0 0 Wlan0
Default 10.147.9.1 0.0.0.0 UG 0 0 0 eth0
[Email protected]:~#
The result is top-down, that is, which one is in front, which one has precedence, none in front, with the last default
For example, add a route (all the network segments destined for 192.168.62 go through the gateway 192.168.1.1)
Route add-net 192.168.62.0 netmask 255.255.255.0 GW 192.168.1.1
Delete a route
Route del-net 192.168.122.0 netmask 255.255.255.0

Do not write the gateway when deleting

Ways to add routes under Linux:

One: Use the route command to add
Routes added using the route command, the machine restarts, or the network card restarts, the route is invalidated, by:
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.1
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 eth1
Add a default gateway
# route add default GW IP
Delete route
# route del–host 192.168.168.110 Dev eth0

Two: The method of setting the permanent route 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 end in/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, modify, delete routes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.