


Detailed explanation of route command
Detailed explanation of route command
The route command of Linux system is used to display and manipulate the IP routing table (show / manipulate the IP routing table). To achieve communication between two different subnets, you need a router that connects the two networks, or a gateway that is located on both networks at the same time. In a Linux system, routing is usually set up to solve the following problems:
The Linux system is in a LAN, and there is a gateway in the LAN that allows the machine to access the Internet, so the IP address of the machine needs to be Set as the default route for Linux machines. It should be noted that executing the route command directly on the command line to add a route will not be saved permanently. When the network card is restarted or the machine is restarted, the route will become invalid; you can add the route command in /etc/rc.local to ensure This routing setting is permanent.
Recommended: "Linux Tutorial"
1. Command format:
route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]]
2. Command function:
Route command is used to operate the kernel-based ip routing table. Its main function is to create a static route to specify a host or a network through a network interface, such as eth0. When the "add" or "del" parameter is used, the routing table is modified. If there are no parameters, the current contents of the routing table are displayed.
3. Command parameters:
-c Display more information
-n Do not resolve the name
-v Display detailed processing information
-F Display sending information
-C Show route cache
-f Clear the routing table of all gateway entries.
-p makes the route permanent when used with the add command.
add: Add a new route.
del: Delete a route.
-net: The target address is a network.
-host: The target address is a host.
netmask: When adding a network route, a network mask needs to be used.
gw: Route packets through the gateway. Note that the gateway you specify must be reachable.
metric: Set the routing hop count.
Command Specifies the command you want to run (Add/Change/Delete/Print).
Destination specifies the network destination of this route.
mask Netmask Specifies the network mask (also called a subnet mask) associated with the network target.
Gateway Specifies the forward or next hop IP address that can be reached by the address set and subnet mask defined by the network destination.
metric Metric Specifies an integer cost value for the route (from 1 to 9999), which can be used when selecting among multiple routes in the routing table that best matches the destination address of the forwarded packet.
if Interface Specifies the interface index for the interface that can access the target. To obtain a list of interfaces and their corresponding interface indexes, use the display function of the route print command. Interface indexing can be done using decimal or hexadecimal values.
4. Usage example:
Example 1: Display the current route
Command:
route route -n
Output:
[root@localhost ~]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0 e192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0 default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0 [root@localhost ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.120.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0 0.0.0.0 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
Description:
First line Indicates that the address of the network where the host is located is 192.168.120.0. If the data transmission target is to communicate within this LAN, the data packet can be forwarded directly through eth0;
The fourth line indicates that the data transmission purpose is to access the Internet, then Interface eth0 sends the data packet to the gateway 192.168.120.240
where Flags is the routing flag, marking the status of the current network node.
Flags flag description:
U Up means that this route is currently in the startup state
H Host, means that this gateway is a host
G Gateway, means This gateway is a router
R Reinstate Route, a route reinitialized using dynamic routing
D Dynamically, this route is dynamically written
M Modified, this route It is dynamically modified by the routing daemon or director
! Indicates that this route is currently closed
Remarks:
route -n (-n Indicates that the name will not be parsed, and the listing speed will be faster than route)
Example 2: Add gateway/set gateway
Command:
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
Output:
[root@localhost ~]# route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0 [root@localhost ~]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0 224.0.0.0 * 240.0.0.0 U 0 0 0 eth0 default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0 [root@localhost ~]#
Instructions:
Add a route to 244.0.0.0
Example 3: Block a route
Command:
route add -net 224.0.0.0 netmask 240.0.0.0 reject
Output:
[root@localhost ~]# route add -net 224.0.0.0 netmask 240.0.0.0 reject [root@localhost ~]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0 224.0.0.0 - 240.0.0.0 ! 0 - 0 - 224.0.0.0 * 240.0.0.0 U 0 0 0 eth0 default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
Description:
Add a shielded route with the destination address 224.x.x.x and it will be rejected
Example 4: Delete routing record
Command:
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
Output:
[root@localhost ~]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0 224.0.0.0 - 240.0.0.0 ! 0 - 0 - 224.0.0.0 * 240.0.0.0 U 0 0 0 eth0 default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0 [root@localhost ~]# route del -net 224.0.0.0 netmask 240.0.0.0 [root@localhost ~]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0 224.0.0.0 - 240.0.0.0 ! 0 - 0 - default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0 [root@localhost ~]# route del -net 224.0.0.0 netmask 240.0.0.0 reject [root@localhost ~]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0 default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0 [root@localhost ~]#
Description:
Example 5: Delete and add Set the default gateway
Command:
route del default gw 192.168.120.240 route add default gw 192.168.120.240
Output:
[root@localhost ~]# route del default gw 192.168.120.240 [root@localhost ~]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0 [root@localhost ~]# route add default gw 192.168.120.240 [root@localhost ~]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.120.0 * 255.255.255.0 U 0 0 0 eth0 192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0 10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0 default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0 [root@localhost ~]#
The above is the detailed content of Detailed explanation of route command. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Linux beginners should master basic operations such as file management, user management and network configuration. 1) File management: Use mkdir, touch, ls, rm, mv, and CP commands. 2) User management: Use useradd, passwd, userdel, and usermod commands. 3) Network configuration: Use ifconfig, echo, and ufw commands. These operations are the basis of Linux system management, and mastering them can effectively manage the system.

In Debian systems, the log files of the Tigervnc server are usually stored in the .vnc folder in the user's home directory. If you run Tigervnc as a specific user, the log file name is usually similar to xf:1.log, where xf:1 represents the username. To view these logs, you can use the following command: cat~/.vnc/xf:1.log Or, you can open the log file using a text editor: nano~/.vnc/xf:1.log Please note that accessing and viewing log files may require root permissions, depending on the security settings of the system.

The readdir function in the Debian system is a system call used to read directory contents and is often used in C programming. This article will explain how to integrate readdir with other tools to enhance its functionality. Method 1: Combining C language program and pipeline First, write a C program to call the readdir function and output the result: #include#include#include#includeintmain(intargc,char*argv[]){DIR*dir;structdirent*entry;if(argc!=2){

DebianSniffer is a network sniffer tool used to capture and analyze network packet timestamps: displays the time for packet capture, usually in seconds. Source IP address (SourceIP): The network address of the device that sent the packet. Destination IP address (DestinationIP): The network address of the device receiving the data packet. SourcePort: The port number used by the device sending the packet. Destinatio

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

This article will explain how to improve website performance by analyzing Apache logs under the Debian system. 1. Log Analysis Basics Apache log records the detailed information of all HTTP requests, including IP address, timestamp, request URL, HTTP method and response code. In Debian systems, these logs are usually located in the /var/log/apache2/access.log and /var/log/apache2/error.log directories. Understanding the log structure is the first step in effective analysis. 2. Log analysis tool You can use a variety of tools to analyze Apache logs: Command line tools: grep, awk, sed and other command line tools.

This article describes how to clean useless software packages and free up disk space in the Debian system. Step 1: Update the package list Make sure your package list is up to date: sudoaptupdate Step 2: View installed packages Use the following command to view all installed packages: dpkg--get-selections|grep-vdeinstall Step 3: Identify redundant packages Use the aptitude tool to find packages that are no longer needed. aptitude will provide suggestions to help you safely delete packages: sudoaptitudesearch '~pimportant' This command lists the tags

To configure the DNS settings for the Debian mail server, you can follow these steps: Open the network configuration file: Use a text editor (such as vi or nano) to open the network configuration file /etc/network/interfaces. sudonano/etc/network/interfaces Find network interface configuration: Find the network interface to be modified in the configuration file. Normally, the configuration of the Ethernet interface is located in the ifeth0 block.
