Linux Troubleshooting network problems

Foreword

As a software engineer, Linux-related knowledge is an essential skill points, while network problems are often the first contact with Linux beginners encounter a stumbling block, this blog will explain the system to solve a network problem Linux the general methodology, a scientific methodology can often achieve a multiplier effect.

The focus of this blog is not to explain the knowledge of computer networks, it is assumed that you have a certain network infrastructure, if not, you can take a look at the recommended reading list at the end of my article.

This blog is based on Ubuntu 18.04 to write, use cat /etc/issuecan check the version for other versions of Linux distributions, some commands might be different, but the essence is the same.

Overall picture

First of all, to solve network problems, which Mody you have to understand the hierarchical structure and topology of the network , it makes you have a macro perception of the entire network, there is a great help to you locate the problem.

Network hierarchy

Hierarchical and network topology

  1. For the hierarchical structure of the network, you need to know what each floor common agreement and understanding of the relevant principles of the agreement, because the back of the tools we use are referred to the appropriate protocol to work.
  2. For the topology of the network, you need to know in a packet network and public network , there is how the flow of switches and routers What is the difference of yes.

identify the problem

Network is a problem, the problem is nothing more than hardware and software problems.

hardware problem

The surface of the broad issues involved, such as the network cable is not plugged in, the router is broken, and so on. In fact, this is a small probability event, usually out of the question may have relevant professional maintenance staff to solve, as a software engineer, the point we are concerned that a software problem.

Software Problems

For the average computer user, unable to get online, and it refers to the large probability can not be on sites such as Baidu. But as software engineers, we have to clear Why not on the net, and in the end is that a layer of the network there is a problem?

General troubleshooting ideas, there are two, bottom-up and top-down , these two ideas are essentially the same, this article on the bottom-up to troubleshoot network problems.

NIC is working properly? (Link layer)

Strictly speaking, this problem is a hardware problem, but we can use the command to operate the card, in the software industry, a reboot may solve most of the problems.

As shown below, use the ifconfigView card information, results displayed should have multiple, virtual machine created a virtual network card, and your real computer's network card, network card of our attention is generally called ens33 , or eth0 , this is not important, just a name.

View network information ifconfig

We then use ifdown ens33to turn it off, then use ifup ens33to start it (ens33 is the name of your card), in most cases, will be able to restart normal access card network.

NIC configuration is correct? (Network layer)

In the case of the card is not damaged after the restart still can not access the network, which we should troubleshoot the network layer, which is the network card configuration information is normal? Mainly in the following four points:

  1. IP addresses

    We all know the IP address is used to identify the address of your computer on the Internet, at present we are using IPv4 address in most cases, but in the near future, IPv6 will spread. (32-bit IPv4 address is now far not enough)

    Shown above inet 192.168.81.129is my IP address.

  2. Subnet Mask

    IP address and subnet mask phase and can get the network number, is the network segment where you are.

  3. Gateway

    Gateway is your data packets sent from the network to the public network must pass, in general, is the first or the last address of the network segment.

    As shown below, we can use route -nto view information.

    route

  4. DNS server

    DNS is used to resolve domain name server then returns the corresponding IP address to you, such as www.baidu.com, the correspondence is 182.61.200.7, common DNS server has 1.1.1.1,8.8.8.8,114.114.114.114

    As shown below, we can use the cat /etc/resolv.confcommand to view the DNS server address set in the machine.

    DNS address lookup

note! ! !

Your IP address , subnet mask , gateway , the DNS servers are normal is a necessary condition for normal operation of the network.

Under normal circumstances, your DHCP server will automatically assign IP, and related settings for you. If the DHCP server is not working, this time you will need to manually assign the correct IP, and ensure that the configuration is correct.

(In view of space reasons, and this article is mainly about a scientific methodology, so how to manually configure this information, please review other information)

test! ! !

After these configurations are correct, we can use the ping command to test the network layer is working correctly. (Note that some LAN router is set to block ping, which caused great distress to us troubleshoot network problems)

  • First, we can ping the gateway IP address, or other IP address on the LAN, if normal operation, in which it can be confirmed that the LAN we are normal.

(Note: Windows system firewall by default is not the ICMP protocol (ping command uses ICMP is the protocol), so you ping a computer with Windows systems may fail)

ping gateway

  • Second, we can ping Baidu, if the work, which it explained in our public network is normal.

Services are listening port? (Transport Layer)

For general users, can ping Baidu, enough to meet his daily needs, but for our software engineers, we will build their own service site, provide their own application service, or we will be configured VPS enable access to Google.

When you have a good VPS configuration according to the tutorial found not use, and the use of the first two steps of the method, found VPS Internet can be normal, this time the problem is a high probability your VPS services.

Server

  • First check VPS process is working properly? Use ps -aux|grep docker(insert one Kazakh, use docker to deploy our application is simply too cool)

Normal process

  • See if VPS normal listening port?

Port Listener

Client

If the above two steps are not the problem, but still unable to access Google on your client, then what you need it to test whether the port is really through, namely whether the customer end and server can establish a session.

As shown below, we can use the telnet ip地址 端口test.

telnet connection is successful

If the connection fails, it means that the port is unreasonable at this time is likely to be a problem with VPS configuration files, you need to do anything else investigation, as shown below.

telnet connection fails

Firewall, security groups

If the above tests are not the problem, what the problem is a high probability what firewall or security policy group (bought Tencent Ali clouds or cloud the students should know), in most cases, the protocol we used and listening ports will not be firewall blocked, so little time to deal with such cases, in view of space reasons, we do not talk about it.

The service is working properly? (Application Layer)

This is usually obvious, such as all the common 404 NOT FOUND, which is either a wall or a server error occurred. General error information more obvious.

to sum up

Beginner computer network, I felt knowledge are many and complex, but simple reading, the effect is relatively poor, and easy to fall asleep. In fact, when we started to learn a knowledge of, the first thing is to establish the overall macro-knowledge, then learning part of the work is often used, such as the basic concept application layer, transport layer, network layer. Basic and common knowledge are after school, combined with his interest to go in-depth learning principles. We know 28 principles , namely 20% to 80% of knowledge to solve problems.

Recommended information

"Computer Network" edited by Xie Xiren (B station with better Han Ligang teacher video lessons effect)

Guess you like

Origin www.cnblogs.com/yahuian/p/11407090.html