In the process of daily operation and maintenance of the project, we often encounter all kinds of strange network problems. Then troubleshooting network problems, become a qualified programmer essential skills. This section lists some common commands to quickly locate network faults.

ping

This is a common little tool used to check whether packets can be exchanged successfully between two servers. The ping command sends ICMP packets to the host. If the ping succeeds, the network link between the two hosts is normal. If the ping fails, check whether the ping service is disabled. If the ping service is not disabled, check the network connection between the two parties.

telnet

This command is used to check the network connectivity of the peer port. If Telnet works, the TCP three-way handshake is successfully established, that is, the network layer is unblocked. If Telnet fails, check whether the corresponding service port has been enabled. If yes, check the firewall policies of both parties.

ifconfig

In addition to viewing network card information, the ifconfig command can also modify network configurations. For example, check the nic information ifconfig -a; Ifconfig eth0 up; Disable operations such as ifconfig eth0 Down on the NIC.

In addition to running the ifconfig command to view and configure the NIC information, you can also run the IP link show command to display the NIC information. Disable the NETWORK adapter IP link set up eth1.

Note: In the case of SSH connection, do not operate.

route

The route command is used to view and configure server routing information. Like see routing information route – n or adding or deleting routing information route the route – nee {add | del} -.net {NETWORK – ADDRESS} netmask netmask dev attach {INTERFACE – NAME}, and so on.

You can also run the IP route show command to view routing information. Is equivalent to route-n. The IP route command is recommended.

traceroute

This command is used to view the routing path from the source address to the destination address. For example, traceroute www.baidu.com is used to determine which network devices have passed between you and the target address. Under Windows is tracert

netstat

This command is more powerful, but also programmers use more of a daily command. This command displays the network status of the server. For example, netstat -a displays all current socket connections of the server. Display UDP/TCP port usage netstat -apu/netstat -apt; Display network statistics netstat -s; Check the state of the port 8080 netstat – anp | grep, 8080.

The equivalent of netstat is the SS directive. Ss-l lists all ports that are already open on this machine. Ss -t/u -a Displays all TCP/UDP links. Check which process SS-TP a link belongs to. Check the local port status ss -t SRC IP :8080. The SS directive is preferred here.

tcpdump

Network packet capture tool. When a strange network problem occurs, it uses tcpdump to capture network packets and analyze the problem. Packet capture based on source IP address tcpdump -i eth2 SRC 192.168.199.100 Captures only network packets whose source IP address is 192.168.199.100 that pass through eth2. You can also specify a port to capture packets, such as tcpdump SRC port 8088. In short, this command is very powerful, so I don’t want to go into more details here.

nmap

This is a network sniffing and scanning tool, do network security partners will be more familiar. It is often used to check which ports are open on the host. For example, you can check which ports are open on the host nmap-ps 192.168.199.100. You can also check the operating system nmap-o 192.168.199.100 of the target IP address. In short, the command to do network security will use more, programmers will use less, interested in in-depth study, the command and its powerful.

conclusion

The gadget mentioned above, for some problems, can achieve the same effect by using two different instructions. For example, ifconfig -a and IP link show; Route-n and IP route show; And Netstat and SS. This is because commands such as ifconfig and netstat come from the Net-Tools toolkit, while directives such as IP Link and ss come from the iproute2 toolkit. Net-tools is no longer in development. It does not come with the default tool kit on many new operating systems. You need to install it separately if you want to use it. Iproute2 is a replacement for Net-Tools, and many new versions of Linux are installed by default. And many of the instructions in the Iproute2 package are more powerful in terms of functionality and performance than those provided in the Net-Tools package.

Here I found a picture from the Internet to illustrate the comparison of instructions between the two kits.

The best time to plant a tree was ten years ago. The second best time is now. ** For those of you who are learning to program or are working, if you want to improve your programming skills, help you improve! ** I may be able to help you here ~

C language C++ programming learning exchange circle, **QQ group [951258402] ** wechat public number: C language programming learning base

Share (source code, project actual combat video, project notes, basic introduction tutorial)

Welcome to change careers and learn programming partners, use more information to learn and grow faster than their own thinking oh!

Programming learning video sharing: