Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the route command in Linux

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use the route command in Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The common Linux command route command is used to display and set the network routing table in the Linux kernel, and the route set by the route command is mainly static route. To achieve communication between two different subnets, you need a router connecting two networks, or a gateway located on both networks.

Route displays and sets the static routing table in Linux

Add that setting routing in the Linux system is usually to solve the following problems: the Linux system in a local area network, the local area network has a gateway that allows the machine to access the Internet, so it is necessary to set the ip address of this machine to the default route of the Linux machine. It is important to note that the route will not be saved permanently by executing the route command directly under the command line, and the route will become invalid when the network card is restarted or the machine is rebooted; you can add the route command in / etc/rc.local to ensure that the route setting is permanent.

Syntax route (options) (parameters) option-A: set the address type;-C: print the route cache for the Linux core;-v: details mode;-n: display the IP address in numeric form without performing a DNS reverse lookup;-e:netstat format shows the routing table;-net: the routing table to a network;-host: the routing table to a host. Parameter Add: add the specified route record; Del: delete the specified route record; Target: destination network or destination host; gw: set the default gateway; mss: set the maximum block length (MSS) of the TCP; unit MB; window: specify the size of the TCP window connected through the TCP connection through the routing table; dev: the network interface represented by the route record. The example shows the current route:

[root@localhost ~] # route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 112.124.12.0 * 255.255.252.0 U 000 eth2 10.160.0.0 * 255.255.240.0 U 000 eth0 192.168.0.0 10.160.15 . 247 255.255.0.0 UG 0 0 0 eth0 172.16.0.0 10.160.15.247 255.240.0.0 UG 0 0 0 eth0 10.0.0.0 10.160.15.247 255.0.0.0 UG 0 0 0 eth0 default 112.124.15.247 0.0.0.0 UG 0 0 eth2 [root@localhost ~] # route-n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 112.124.12.0 0.0.0.0 255.255.252.0 U 000 eth2 10.160.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0 192.168.0.0 10.160.15.247 255.255.0.0 UG 0 0 0 eth0 172.16.0.0 10.160.15.247 255.240.0.0 UG 0 0 0 eth0 10.0.0.0 10.160.15.247 255.0.0.0 UG 0 0 0 eth0 0 .0.0.0 112.124.15.247 0.0.0.0 UG 2000 eth2 where Flags is the route flag Marks the status of the current network node, and the Flags flag states:

U Up indicates that this route is currently started.

H Host, indicating that this gateway is a host.

G Gateway, indicating that this gateway is a router.

R Reinstate Route, a route that is reinitialized with dynamic routing.

D Dynamically, this route is written dynamically.

M Modified, this route is dynamically modified by the routing daemon or director.

! Indicates that this route is currently turned off.

Add Gateway / set Gateway:

Route add-net 224.0.0.0 netmask 240.0.0.0 dev eth0 # adds a route to 244.0.0.0. Block a route:

Route add-net 224.0.0.0 netmask 240.0.0.0 reject # adds a masked route, and the destination address 224.x.x.x will be rejected. Delete routing record:

Route del-net 224.0.0.0 netmask 240.0.0.0 route del-net 224.0.0.0 netmask 240.0.0.0 reject remove and add settings default gateway:

Route del default gw 192.168.120.240 route add default gw 192.168.120.240 and above are all the contents of this article entitled "how to use route commands in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report