How to add a soft route in Linux

Source: Internet
Author: User

Method 1 for adding a soft route in Linux:

 
 
  1. route add -net 172.16.6.0 netmask 255.255.255.0 gw 172.16.2.254 dev eth0/*  

Add a network 172.16.6.0/24 to go through 172.16.2.254 eth0 * // *-net to add network-host to add host, netmask subnet mask, gw gateway, dev device, and device, here is your Nic name */route del gw 172.16.2.254/* delete default gateway 172.16.2.254 */route del-net 172.16.86.0/24/* delete default network 172.16.86.0 */route/* display currentRoutingTable */This method is commonly used, but sometimes it does not work when you delete or delete a soft route. What is the prompt: SIOCADDRT: unable to access the network, so we can use the following method.

Method 2:

The implemented functions are the same as those above.

 
 
  1. ip route add 172.16.6.0/24 via 172.16.2.254 dev eth0   
  2.  
  3. ip route del gw 172.16.2.254  
  4.  
  5. ip route del 172.16.6.0/24 dev eth0ip route 

Method To delete: Add a route:

The following is a code snippet:

 
 
  1. route add -net 10.0.0.0 netmask 255.0.0.0 dev eth0 

Delete A route:

The following is a code snippet:

 
 
  1. route del -net 10.0.0.0 netmask 255.0.0.0 dev eth0 

Add default route:

The following is a code snippet:

 
 
  1. route add default gw 10.0.0.1 

Delete default route:

The following is a code snippet:

 
 
  1. route del default gw 10.0.0.1 

Or

The following is a code snippet:

 
 
  1. route del default 

How to add a route in linux:

Use the route command to add

If you use the route entry added by the route command, the route becomes invalid after the machine is restarted or the NIC is restarted. The method is as follows:

The following is a code snippet:

 
 
  1. // Route entry to the host
  2.  
  3. # Route add-host 192.168.168.110 dev eth0
  4.  
  5. # Route add-host 192.168.168.119 gw 192.168.168.1
  6.  
  7. // Route added to the network
  8.  
  9. # Route add-net IP netmask MASK eth0
  10.  
  11. # Route add-net IP netmask MASK gw IP
  12.  
  13. # Route add-net IP/24 eth1
  14.  
  15. // Add a default gateway
  16.  
  17. # Route add default gw IP
  18.  
  19. // Delete a route
  20.  
  21. # Route del-host 192.168.168.110 dev eth0

How to Set a permanent route in linux:

1. Add in/etc/rc. local

The following is a code snippet:

 
 
  1. route add -net 192.168.3.0/24 dev eth0  
  2.  
  3. 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:

The following is a code snippet:

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

You should be able to master and understand the method of adding soft routes in Linux. We will continue to sort out relevant content for your reference. For more highlights, see: In-depth Analysis of Using Linux + Zebra to build a soft route system

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.