Fix the problem of not connecting to the Internet in Linux

Fix the problem of not connecting to the Internet in Linux

Fix the problem of not connecting to the Internet in Linux

Maybe for you, who owns a Linux server or a Linux desktop operating system, there will be a problem of not connecting to the Internet, or a severe drop in Internet speed, or your Internet will not work at all in a certain program. In this article, we will examine the methods that solve the problems caused by the lack of Internet connection in Linux .

Before doing anything, we must make sure that our Internet is connected in Linux with the following command. This command is Google’s dns, and if the Internet is connected, the ping must be complete.

ping -c 4

The output of the above command should be as follows. Otherwise, there is a possibility that your internet will be interrupted.

PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=58 time=1.68 ms
64 bytes from icmp_seq=2 ttl=58 time=1.70 ms
64 bytes from icmp_seq=3 ttl=58 time=1.71 ms
64 bytes from icmp_seq=4 ttl=58 time=1.69 ms

--- ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 1.686/1.699/1.718/0.051 ms

The things that can fix the lack of Internet connection in Linux are:

  • Checking the DNS server
  • Restart the internet service
  • Network card settings
  • Checking and troubleshooting the network card
  • Firewall settings
  • And …

DNS server check

To check DNS, enter the following command in the terminal environment:

sudo cat /etc/resolv.conf

The output of the command should be as follows:


If your output is anything other than this, you can edit it with the nano command and paste the above text into it.

sudo nano /etc/resolv.conf

And then confirm and save the file by holding the combination key CTRL and X and then with Y.

Restart the Internet service

If the mentioned methods did not solve your Internet interruption problem in Linux, restart your operating system’s Internet service with the following commands, because it is possible that some services have a problem, and with this work, it will return to its default state and the Internet interruption problem fix you

Command to restart internet services for Ubuntu, debian and kalilinux operating systems

sudo service networking restart

The command to restart the network manager

sudo service network-manager restart

Command to restart internet services for RedHAT and CentOS operating systems

sudo service network restart

Network card settings

One of the reasons that is very effective is the deactivation of the network card. We can check the correct operation of our Linux network card with the following command.

ip addr

My network card named eth0 is here, and as you can see, it got an IP from the router and there is no problem in the configuration of the network card.

It is also possible that the name of the network card is different in your system. So put the name of your network card in the command below.

Use the following command to activate the inactive network card.

sudo ifup network card name

Use the following command to disable the active network card.

sudo ifdown Network card name

If your network card has an error and is not disabled, you can use this command.

sudo ifdown --force The name of the network card

Use the following command to activate it.

sudo ifup network card name

Network check and troubleshooting

To check the Internet network and ISP, we can use the following command to find the exact location of our Internet.

For debian and ubuntu

traceroute -4

For RedHat and CentOS


If the process is done completely and correctly, the output is like this:

traceroute to (, 30 hops max, 60 byte packets
1_gateway ( 3.368 ms 3.367 ms 3.432 ms
2 * * *
3 ( 84.501 ms 96.662 ms 96.555 ms
4 ( 96.114 ms 96.044 ms 96.294 ms
5 ( 99.350 ms 96.353 ms 99.129 ms
6 * * *
7 ( 66.813 ms 66.721 ms 65.910 ms
8 ( 64.090 ms 64.000 ms 63.533 ms
9 ( 63.457 ms 62.483 ms 62.386 ms
10 ( 62.013 ms 79.632 ms 79.657 ms
11 ( 83.412 ms 82.312 ms 82.575 ms
12 ( 84.991 ms 84.919 ms 79.934 ms
13 ( 79.811 ms 79.429 ms 103.539 ms
14 ( 83.904 ms 82.089 ms 80.381 ms
15 ( 80.417 ms 80.624 ms 80.545 ms
16 ( 91.927 ms 89.772 ms 89.220 ms
17 ( 92.004 ms 91.606 ms 91.540 ms
18 ( 207.375 ms ( 92.005 ms 90.894 ms
19 ( 80.345 ms ( 196.298 ms 196.007 ms
20 ( 188.921 ms 195.807 ms ( 168.200 Ms
21 ( 167.552 ms ( 167.360 ms *
22 ( 175.274 ms * 135.098 ms
23 * ( 134.970 ms ( 164.028 ms

Firewall settings

After checking the connection and its correctness, we should check the firewall rules. For this purpose, we use the following command.

sudo iptables -L

The iptabels firewall checks all ports and applications connected to the Linux Internet.

Chain INPUT (policy ACCEPT)
target prot opt ​​source destination
ACCEPT all -- anywhere anywhere the RELATED, ESTABLISHED
ACCEPT tcp -- anywhere anywhere The firewall dpt:http
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
DROP all -- anywhere anywhere

Chain Forward (policy ACCEPT)
target prot opt ​​source destination

Chain OUTPUT (policy ACCEPT)
target prot opt ​​source destination

For example, here we have imposed restrictions on http and ssh access to the server, and you can check which option blocks ping on your server or system.

We hope that the mentioned methods are the right solution for your problem.

support hosting100