Route table configuration command

Source: Internet
Author: User


Route table configuration command view route reference routeDestination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0*255.255.255.0 U 0 0 0 eth0 169.254.0.0*255.255.0.0 U 0 0 0 eth0 default 192.168.0.1 0.0.0.0 UG 0 0 0 0 eth0 route command output description Destination CIDR block or host Gateway address, "*" indicates the network to which the host belongs and does not require the routing Genmask network mask www.2cto.com Flags. Some possible tags are as follows: u-route is the active H-target is a host G-route pointing to the gateway R-restore the table items generated by dynamic routing D-install M-by route dynamically by the routing background program background program modification! -Route rejection
Metric route distance, the number of intermediate connections required to reach the specified network (not used in linux kernel) Ref route entry references (not used in linux kernel) use the number of times this route item is searched by the routing software Iface the output interface corresponding to this route table Item 1: Use the route command to add the route entry added using the route command, after the machine is restarted or the NIC is restarted, the route becomes invalid. Method: // route reference added 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 reference added to the network # route add-net 192.168.1.11 netmask route 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 www.2cto.com // add default Gateway reference # route add default gw 192.168.2.1 // Delete route reference # route del-host 192.168.1.11 dev eth0 2: how to Set a permanent route in linux:
1. in/etc/rc. add method in local: Reference 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 method in/etc/sysconfig/network: GATEWAY = gw-ip or GATEWAY = gw-dev 3. /etc/sysconfig/static-routes: (if there is no static-routes, manually create such a file) reference any net 192.168.3.0/24 gw 192.168.3.254 any net 10.250.228.128 netmask 255.255.192 gw 10.250.228.129 www.2cto.com 4. enable IP forwarding: Reference # echo "1">/proc/sys/n Et/ipv4/ip_forward (temporary) # vi/etc/sysctl. conf --> net. ipv4.ip _ forward = 1 (permanently enabled) If. adding a route in local will cause the NFS to be unable to be automatically mounted, so using static-routes is the best method. Both the restart system and the service network restart will take effect in the order of linux Startup, rc. the content in local is executed only after all linux services are started. That is to say, the content is executed only after netfs, that is to say, when netfs is started, the static route on the server is not added, so netfs cannot be mounted successfully. What is the static-routes file? This is a file called when the network script is executed. The file is placed in the/etc/sysconfig directory, and the location in the network script is: reference # Add non interface-specific static-routes. if [-f/etc/sysconfig/static-routes]; then grep "^ any"/etc/sysconfig/static-routes | while read ignore args; do/sbin/route add-$ args done www.2cto.com fi can be seen from this script. This is the method for adding static routes, static-routes is written as any net 192.168.0.0/16 gw gateway ip address. In this case, the route is automatically added when the network script is started. Twork is started in front of netfs. It is normal when nfs is mounted. In this case, if you need to add a static route, the use of the static-routes file is better than the use of rc. local is good, and when the network configuration is changed and the network script needs to be restarted, the corresponding static route can be automatically added, but if rc is used at this time. local, when the network service is restarted, the originally added static route disappears.

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.