Home >Operation and Maintenance >Linux Operation and Maintenance >What are the network commands in linux
Linux has a variety of built-in network commands: 1. ping, used to test whether the TCP/IP network is smooth or test the network connection speed; 2. telnet, used to log in to the remote host and manage the remote host; 3. netstat, used to print status information of network systems in Linux; 4. ifconfig, etc.
#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
There are many kinds of network commands under Linux. Let me share with you some common network commands.
1. ping
The ping command is used to test whether the TCP/IP network is smooth or to test the network connection speed. It is very useful for determining whether the network is connected correctly and the status of the network connection. it works. Simply put, ping is a test program. If ping runs correctly, it can generally eliminate faults in the network access layer, network card, Modem input and output lines, cables and routers, thereby narrowing the scope of the problem.
The principle of the ping command is based on the unique IP address of the computer. When the user sends a data packet to the destination address, the other party will return a data packet of the same size. Based on the returned data packet, the user can determine the existence of the destination host. , and initially determine the operating system of the destination host.
(1)Command format
destination address Refers to the IP address, host name or domain name of the computer under test. The ping command contains 12 parameters, all parameters can be viewed by executing ping. As shown below:
(2) Example
Note: The ping command under Linux is different from the ping command under Windows. Ctrl C is required to terminate
(Linux The difference from the ping command under Windows)
(3) Option
-d: Use the SO_DEBUG function of Socket;
-c: Set the number of times to complete the request response;
-f: Limit detection;
-i: Specify the interval between sending and receiving information;
-L: Use the specified network interface to send data packets;
-l: </preload></strong>Set the data packet to be sent before sending the request information; <br><strong>-n: </strong>Only output the numerical value; <br><strong>-p< ;Template style>: </strong> Set the template style for filling the data packet; <br><strong>-q: </strong>Do not display the instruction execution process, except for the relevant information at the beginning and end; <br><strong> -r: </strong> Ignore the ordinary Routing Table and send the data packet directly to the remote host; <br><strong>-R: </strong>Record the routing process; <br><strong>-s<data packet size>:</data></strong>Set the size of the data packet; <br><strong>-v:</strong>Display the execution process of the instruction in detail. <br><strong>-t<survival value>: Set the size of the survival value TTL</survival></strong></p></blockquote> <p> Let’s talk about <strong>-c</strong> and <strong>-i</strong>Parameters<br> Among them -c count times, which is the number of pings; -i interval interval, the time space between each ping<br><img title="" alt="What are the network commands in linux" src="https://img.php.cn/upload/article/000/000/024/a0630bda4c67c0c43cf5996ca6b309e3-2.png"></p> <hr> <p><strong><span style="font-size: 18px;">2. telnet</span></strong></p> <p>The telnet command is used to log in to the remote host and manage the remote host. Because telnet uses clear text to transmit messages, its security is not good. Many Linux servers do not open the telnet service and use the more secure ssh method instead. </p> <h5 id="用法-1">Usage</h5> <p>(1)Command format:</p> <ul><li><strong>telnet (option) (parameter) </strong></li></ul> <p> (2) Example </p> <p><img title="" alt="What are the network commands in linux" src="https://img.php.cn/upload/article/000/000/024/aeafb415bfec575962a1c11f68141be7-3.png"></p> <p> (3) Parameter </p> <ul> <li> <strong>Remote host: </strong>Specify the remote host to log in for management</li> <li> <strong>Port: </strong>Specify the port number used by the TELNET protocol </li> </ul> <p> (4) Option</p> <blockquote><p><strong>-8:</strong>Allows the use of 8-bit character data, including input and output; <br><strong>-a:</strong>Try to automatically log in to the remote system; <br><strong>-b<host alias>: </host></strong>Use an alias to specify the remote host name; <br><strong>-c: </strong>Do not read the .telnetrc file in the user-specific directory; <br><strong>-d: </strong>Start debugging mode; <br><strong>-e<escape character>:</escape></strong>Set the escape character; <br><strong>-E:</strong>Filter out the escape character; <br><strong>-f: </strong>The effect of this parameter is the same as specifying the "-F" parameter; <br><strong>-F: </strong>When using Kerberos V5 authentication, adding this parameter can The host's authentication data is uploaded to the remote host; <br><strong>-k<domain name>:</domain></strong>When using Kerberos authentication, add this parameter to let the remote host use the specified domain name instead of the host's Domain name; <br><strong>-K:</strong>Do not automatically log in to the remote host; <br><strong>-l<user name>:</user></strong>Specify the user name to log in to the remote host; <br><strong>-L:</strong>Allow output of 8-bit character data; <br><strong>-n<record file>:</record></strong>Specify the file to record relevant information; <br><strong>-r:</strong>Use a user interface similar to the rlogin command; <br><strong>-S<service type>: </service></strong>Set the ip TOS information required for the telnet connection; <br><strong>-x:</strong> Assume that the host has the function of supporting data encryption, use it; <br><strong>-X<authentication mode>:</authentication></strong>Close the specified authentication mode. </p></blockquote> <hr> <p><strong><span style="font-size: 18px;">3. netstat</span></strong></p> <p> The netstat command is used to print the status information of the network system in Linux, which allows you to Know the network situation of the entire Linux system</p> <h5 id="用法-2">Usage</h5> <p> (1) Command format</p> <ul><li><strong>netstat (option)</strong></li></ul> <p> (2) Options </p> <blockquote><p><span style="color:red"><strong>-a or –all: </strong>Display all sockets in the connection; </span> <br><strong>-A< ;Network type> or –<network type>: </network></strong> List the relevant addresses in the connection of this network type; <br><span style="color:red"><strong>-c or –continuous: </strong>Continuous listing Network status; </span> <br><strong>-C or –cache: </strong>Display cache information of router configuration; <br><strong>-e or –extend: </strong>Display other network-related information; <br><strong>-F or –fib: </strong>Display FIB; <br><strong>-g or –groups: </strong>Display the multicast function group member list; <br><strong>- h or –help: </strong>Online help; <br><strong>-i or –interfaces:</strong>Display network interface information form; <br><span style="color:red"><strong>-l or –listening:</strong> Display the Socket of the server being monitored; </span> <br><strong>-M or –masquerade: </strong>Display the disguised network connection; <br><span style="color:red"><strong>-n or –numeric: </strong>Use the IP address directly instead of passing the domain name server; </span> <br><strong>-N or –netlink or –symbolic: </strong>Display the symbolic link name of the network hardware peripheral device; <br><strong>- o or –timers: </strong>Display timers; <br><span style="color:red"><strong>-p or –programs: </strong>Display the program identification code and program name that is using Socket; </span> <br><strong>-r or –route: </strong>Display Routing Table; <br><strong>-s or –statistice: </strong>Display network work information statistics table; <br><span style="color:red"><strong>-t or –tcp : </strong> Display the connection status of the TCP transmission protocol; </span> <br><span style="color:red"><strong>-u or –udp: </strong> Display the connection status of the UDP transmission protocol; </span> <br><strong>-v or –verbose: </strong> Display the instruction execution process; <br><strong>-V or –version: </strong>Display version information; <br><strong>-w or –raw: </strong> Display the connection status of RAW transmission protocol; <br><strong>-x or –unix: </strong>The effect of this parameter is the same as specifying the "-A unix" parameter; <br><strong>-ip or –inet: </strong>The effect of this parameter is the same as specifying the "-A inet" parameter</p></blockquote> <p>(3) Example</p><pre class="brush:js;toolbar:false;">netstat -a //列出所有端口 netstat -at //列出所有tcp端口 netstat -au //列出所有udp端口 Display all TCP ports here
netstat -l //只显示监听端口 netstat -lt //只列出所有监听 tcp 端口 netstat -lu //只列出所有监听 udp 端口Compared with the picture above, you can see that only the TCP ports in the listening state are displayed
##4 , ifconfig
The ifconfig command is used to configure and display the network parameters of the network interface in the Linux kernel. The network card information configured with the ifconfig command will no longer exist after the network card is restarted and the machine is restarted. If you want to store the above configuration information in your computer forever, you need to modify the configuration file of the network card. Usage(1)Command format
- ifconfig (parameter)
(2) Example
eth0 represents the first network card, you can see Information about this network card
- HWaddr represents the physical address of the network card, which is the MAC address. You can see that the current MAC address of this network card is: 00:0C:29:A7:C0:6C
- inet addr is used to represent the IP address of the network card. The IP address of this network card is: 192.168.1.106
- Broadcast address Bcast: 192.168.1.255
- Mask address Mask: 255.255.255.0
lo represents the loopback address of the host. This is generally used to test a network program, but does not want users on the LAN or external network to view it. It can only be run and viewed on this host. network interface.
(3) Parameters
##add
: Set the IP address of the network device IPv6
del: Delete the IP address of the network device IPv6
down:Close the specified network device
io_addr:Set the I/O of the network device O address
irq: Set the IRQ of the network device;
media: Set the media type of the network device;
mem_start:Set the starting address occupied by the network device in the main memory;
metric:Specify the number of times the data packet is transmitted when, the number to be added;
mtu:Set the MTU of the network device;
netmask:Set the network The subnet mask of the device;
tunnel:Establish the tunnel communication address between IPv4 and IPv6;
up:Start the specified network device;
-broadcast: Treat the data packet sent to the specified address as a broadcast packet;
-pointopoint: with the specified address Establish a direct connection with the network device. This mode has a confidentiality function;
-promisc:Close or enable the promiscuous mode of the specified network device;
IP address:Specify the network The IP address of the device;
Network device: Specify the name of the network device.
5. route
# The route command is used to display and set the network routing table in the Linux kernel. The route command The routes set are mainly static routes.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; it can be added in
Usage(1) Command format
*/etc/rc. Add the route command to local to ensure that the routing settings are permanently valid.( 2) Option
- route (option) (parameter)
(3) Parameters-A: Set the address type;
-C: Print the Linux core routing cache;
-v:Detailed information mode;
-n:Does not perform DNS reverse lookup and directly displays the IP address in numerical form;
-e: Netstat format displays the routing table;
-net: The routing table to a network;
-host: The routing table to a host.(4) ExampleDisplays the current route. From the figure, you can see the change with option -nAdd: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 of TCP ( MSS), in MB
window:Specifies the TCP window size for TCP connections through the routing table
dev:The network interface represented by the routing recordDelete and add settings for the default gateway
6. The arp
#arp command is used to operate the host arp buffer and can display the arp buffer. All entries in the area, delete specified entries or add the correspondence between static IP addresses and MAC addressesUsage(1)Command format(2) Option
- arp (Option) (Parameter)
-a
: Display all entries of the arp buffer
-H:Specify the address type used by the arp instruction
-d: Removes the arp entry for the specified host from the arp buffer
-D:Uses the hardware address of the specified interface
-e: Display the entries in the arp buffer in Linux display style
-i: Specify the network interface to operate the arp buffer
-s: Sets a static mapping of the IP address and MAC address of the specified host
-n: Displays entries in the arp buffer numerically
-v:Display detailed arp buffer entries, including statistics of buffer entries
-f: Set the host's IP address and MAC Static mapping of addresses(3) Parameters
- Host: Query the arp entry of the specified host in the arp buffer.
(4) Example
##7、traceroute
The traceroute command is used to trace the entire path of data packets when they are transmitted on the network. The default size of the data packets sent is 40 bytes.Through traceroute, we can know how the information goes from your computer to the host at the other end of the Internet. What path. Of course, the path a data packet takes from the same starting point (source) to the same destination (destination) may be different every time, but basically the route taken is the same most of the time.
Usage (1) Command format
Traceroute measures how long it takes by sending small packets to the destination device until it returns. Each device on a path is traceroute tested three times. The output results include the time (ms) of each test and the name of the device (if any) and its IP address(2) option
- traceroute (option) (parameter)
(3) Parameters-d: Use Socket level Troubleshooting function
-f:Set the survival value TTL size of the first detected packet
-F:Set not to disconnect Bit
-g:Set the source routing gateway, up to 8 can be set
-i:Use the specified network interface to send Packet
-l:Use ICMP response instead of UDP data information
-m:Set the maximum survival value TTL size of the detection packet
-n:Use the IP address directly instead of the host name
-p:Set the communication port of the UDP transmission protocol
- r:Ignore the ordinary Routing Table and send the data packet directly to the remote host
-s(4) Example
- Host: Specify the destination host IP address or host name
It can be seen from the figure that the records start from 1 according to the sequence number. Each record is a hop, and each hop represents a gateway. We You see that each line has three times, the unit is ms, which is actually the default parameter of -q. After the detection packet sends three packets to each gateway, the time it takes for the gateway to respond;
In the later part we will see that some lines are represented by asterisks. When this happens, it may be that the firewall blocks the ICMP return information, so we cannot get any relevant packet return data.
8. The host
host command is a commonly used analysis domain name query tool, which can detect whether the domain name system is working properlyUsage(1)Command format
(2)Option
- host(option)(parameter)
-a:Display detailed DNS information
-c: Specify the query type, the default value is "IN"
-C:Query the complete SOA record of the specified host
-r:Do not use recursive query when querying the domain name
-t: Specify the query domain name information type
-v:Display detailed information about command execution
-a:Display detailed DNS information;
-w:If the domain name server does not give a response message, wait until the domain name server gives a response
-WSpecify the maximum time for domain name query, if within the specified time If the domain name server does not give a response message, exit the command
-4: Use IPv4
-6: Use IPv6(3 ) Parameter
- Host: Host information to be queried
(4) Example
9. tcpdump
The tcpdump command is a tool for capturing data packets. It can print the header information of all data packets passing through the network interface. You can use the -w option to save the packets to a file for later analysis.
Usage
(1)Command format
(2)Option
- ##tcpdump(option)
(3) Example-a:Attempt to convert network and broadcast addresses into names;
-c:Received the specified After the number of data packets is reached, stop the dumping operation;
-d: Convert the compiled data packet encoding into a readable format and dump it to the standard output;
- dd: Convert the compiled data packet encoding into C language format and dump it to the standard output;
-ddd: Convert the compiled data packet encoding into decimal number format , and dump to standard output;
-e: Display the connection-level file header on each column of dumped data;
-f: Display the Internet address in numbers ;
-F:Specify the file containing the expression;
-i:Use the specified network section to send data Package;
-l: Use the buffer of the standard output column;
-n: Do not convert the host’s network address into a name;
-N: Do not list domain names;
-O: Do not optimize packet encoding;
-p: Do not let the network interface enter the promiscuous Mode;
-q: Quick output, only lists a few transmission protocol information;
-r:Read from the specified file Packet data;
-s:Set the size of each packet;
-S:List with absolute rather than relative values Number of TCP associations;
-t:Display timestamps on each column of dumped data;
-tt:Display unformatted on each column of dumped data timestamp;
-T:Force the data packet specified by the expression to be translated into the set packet type;
-v:Display the instruction execution process in detail;
-vv:Display the instruction execution process in more detail;
-x:List the data packets in hexadecimal characters Information;
-w: Write packet data to the specified file.tcpdump: Monitor all data packets flowing on the first network interface (with the -i option, monitor the specified network interface)
Related recommendations: "Linux Video Tutorial"
The above is the detailed content of What are the network commands in linux. For more information, please follow other related articles on the PHP Chinese website!