Add a static route

Source: Internet
Author: User

I. Use the route command in linux 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:
// Route entry to the host
# Route add-host 192.168.1.11 dev eth0
# Route add-host 192.168.1.12 gw 192.168.1.1
// Route added to the network
# Route add-net 192.168.1.11 netmask 255.255.255.0 eth0
# Route add-net 192.168.1.11 netmask 255.255.255.0 gw 192.168.1.1
# Route add-net 192.168.1.0/24 eth1
// Add a default gateway
# Route add default gw 192.168.2.1
// Delete a route
# Route del-host 192.168.1.11 dev eth0


Ii. How to set a permanent route in 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.2.254

2. Add to the end of/etc/sysconfig/network
Method: GATEWAY = gw-ip or GATEWAY = gw-dev

3./etc/sysconfig/static-routes: (manually create such a file without static-routes) (CentOS)
Any net 192.168.3.0/24 gw 192.168.3.254
Any net 10.250.228.128 netmask 255.255.255.192 gw 10.250.228.129
3. Use route in windows to add static routes
Route-p add 210.10.10.0 mask route 240.0 192.168.192.1
HKEY_LOCAL_MACHSYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters \ PersistentRoutes
If the Persistent Routes at the end has the added route, the permanent static route is successfully added :. The locations of permanent routes stored in the registry are:
When used with the Print command, the route list is displayed. The doscommand is route print
To display the complete content of the IP route table, type:
Route print
To display routes starting with 10 in the IP route table, type:
Route print 10 .*
To add a default route entry whose default gateway address is 192.168.12.1, type:
Route add 0.0.0.0 mask 0.0.0.0 192.168.12.1
To add a route entry whose destination is 10.41.0.0, whose subnet mask is 255.255.0.0, and whose next hop address is 10.27.0.1, type:
Route add 10.41.0.0 mask 255.255.0.0 10.27.0.1
To add a permanent route whose destination is 10.41.0.0, The subnet mask is 255.255.0.0, And the next hop address is 10.27.0.1, type:
Route-p add 10.41.0.0 mask route 255.0.0 10.27.0.1
To add a route entry with the target 10.41.0.0, subnet mask 255.0.0, Next Hop address 10.27.0.1, and number of hops 7, type:
Route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 metric 7
To add a route entry whose destination is 10.41.0.0, The subnet mask is 255.0.0, the next hop address is 10.27.0.1, and the interface index is 0x3, type:
Route add 10.41.0.0 mask route 0.0 10.27.0.1 if 0x3
To delete a route whose destination is 10.41.0.0 and subnet mask is 255.255.0.0, type:
Route delete 10.41.0.0 mask 255.255.0.0
To delete all routes starting with 10 in the IP route table, type:
Route delete 10 .*
To change the next hop address of the route whose destination is 10.41.0.0 and whose subnet mask is 255.255.0.0 from 10.27.0.1 to 10.27.0.25, type:
Route change 10.41.0.0 mask 255.255.0.0 10.27.0.25

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.