This article has participated in the good article call order activity, click to see: back end, big front end double track submission, 20,000 yuan prize pool for you to challenge!

A lifelong learner, practitioner, and sharer committed to the path of technology, an original blogger who is busy and sometimes lazy, and a teenager who is occasionally boring and sometimes humorous.

Welcome to search “Jge’s IT Journey” on wechat!

How to Efficiently Manage your Network using the Linux Command line?

preface

In daily work, we often use the Linux server operating system, whether to view the information of network devices, management network interface, download files, debugging network problems or view network statistics, can be completed by command in the terminal.

Ifconfig/IP a

The ifconfig command is similar to the IP a command. It is used to output the configuration and tuning of a network interface. You can easily view the information about an IP address, other network interfaces, the status and names of all enabled network interfaces, or specify the name of a network interface to display the information about an interface.

# ip a
# ifconfig
# ifconfig ens32
Copy the code

Ifdown/ifup

The ifdown and ifup commands are the same as the ifconfig down and ifconfig up commands, which are used to specify the name of the network interface to enable or disable the status. In Ubuntu, you need the root permission to use sudo to execute the ifdown and ifconfig up commands.

# sudo ifdown eth0
# sudo ifup eth0
Copy the code

Third, ping

Ping Sends packets to a specified IP address to test connectivity. Using the -c parameter, you can specify the number of packets to be sent.

The ping command uses THE ICMP transmission protocol.

If the ping succeeds, the system outputs the required response information. If the ping fails, the system displays the response information such as no route or rejection. You can solve the specific network situation according to the output information.

# ping -c 4 www.baidu.com
Copy the code

4. Tracepath/Traceroute

The tracepath and traceroute commands are similar in function and do not require the root permission.

The Tracepath command is pre-installed in Ubuntu, but the traceroute command is not.

Using the tracepath command, you can trace the network path to the specified destination address and output the address information of each hop on each path. When the network is faulty or slow, you can use the tracepath command to find out where the network is broken or slow.

The traceroute command is used to trace the routing path of network packets. The default size of packets is 40Bytes. The routing path of packets from a point of departure to a destination may be different, but it is generally the same.

# tracepath www.baidu.com
# traceroute www.baidu.com
Copy the code

Five, the MTR

MTR command: Combines the ping command and tracepath command into one.

MTR continuously sends packets and shows Host Address, time per hop, etc.

# mtr www.github.com
Copy the code

Press Q or CTRL + C to exit.

Six, ifplugstatus

This command is not installed on the Ubuntu operating system. To install it, run the following command:

# sudo apt install ifplugd
Copy the code

Using the ifplugstatus command, you can view the status of all network interfaces or specify network interfaces.

# ifplugstatus
lo: link beat detected
ens32: link beat detected

# ifplugstatus ens32
ens32: link beat detected
Copy the code

Curl/wget

You can use the curl or wget command to download files directly from the terminal.

To do the following, select “curl” : -o;

# curl -O http://www.freelogovectors.net/wp-content/uploads/2016/12/ubuntu_logo.png % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 282 100 282 0 0 156 0 0:00:01 0:00:01 --:--:-- 156 # ll | grep ubuntu_logo. PNG - rw - r - r - 1 root root 282 October 29 now ubuntu_logo. PNGCopy the code

Wget does not require any parameter options, and the downloaded files will be stored in the current directory;

# wget http://www.freelogovectors.net/wp-content/uploads/2016/12/ubuntu_logo.png # ll | grep ubuntu_logo.png -rw-r--r-- 1 root root 95737 December 13 2016 Ubuntu_logo.pngCopy the code

Eight, the host

The host command is used to perform DNS query.

If the parameter is the domain name, the associated IP address is displayed. If the command parameter is IP, the command outputs the associated domain name.

# host www.sina.com
# host IP Address
Copy the code

Nine, whois

The whois command is used to output whois records of a specified site.

# whois www.github.com
Copy the code

Ten, netstat

The netstat command is used to display statistics about network interfaces, including open sockets and routing tables.

-p: the program corresponding to the opened socket can be displayed.

Proto Recv -q Send -q Local Address Foreign Address State PID/Program name TCP 0 0 Jacktian - virtual - ma: SSH 192.168.1.124:44284 ESTABLISHED 4285 / SSHD: root@pts Active UNIX domain socket (W/O server) Proto RefCnt Flags Type State I-node PID/Program name Path UNIX 2 [] datagram 59572 4296 / systemd/run/user / 0 / systemd/notify Unix 2 [] data at 49351, 3344 / systemd/run/user / 1000 / systemd/notify Unix 3 [] the datagram 19222 1/init /run/systemd/notifyCopy the code

-s: displays detailed statistics on all ports.

# netstat -s Ip: Forwarding: 2 30932 total packets received 2 with invalid headers 11 with invalid addresses 0 forwarded 0 incoming packets discarded  30911 incoming packets delivered 18611 requests sent out 22 outgoing packets dropped Icmp: 5499 ICMP messages received 3 input ICMP message failed ICMP received history Destination unreachable: 141 timeout in transit: 5354 echo requests: 2 Echo replies: 2 7523 ICMP messages sent 0 ICMP messages failed ICMP Destination unreachable: 145 echo requests: 7376 echo replies: 2Copy the code

For example, view the information about port 22 based on the parameters.

22 TCP 0 0 # netstat anpt | grep 0.0.0.0:22 0.0.0.0: * 979 / SSHD LISTEN TCP 0 36 192.168.1.142:22 192.168.1.124:44284 ESTABLISHED 4285/sshd: root@pts tcp6 0 0 :::22 :::* LISTEN 979/sshdCopy the code

Original is not easy, if you think this article is a little useful to you, please give me a like, comment or forward for this article, because this will be my power to output more quality articles, thanks!

By the way, dig friends remember to give me a free attention yo! In case you get lost and you can’t find me next time.

See you next time!