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 8.8.8.8
The output of the above command should be as follows. Otherwise, there is a possibility that your internet will be interrupted.
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=58 time=1.68 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=58 time=1.70 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=58 time=1.71 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=58 time=1.69 ms
--- 8.8.8.8 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:
nameserver 1.1.1.1
nameserver 1.0.0.1
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 8.8.8.8
For RedHat and CentOS
tracepath 8.8.8.8
If the process is done completely and correctly, the output is like this:
traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
1_gateway (192.168.43.1) 3.368 ms 3.367 ms 3.432 ms
2 * * *
3 10.40.72.17 (10.40.72.17) 84.501 ms 96.662 ms 96.555 ms
4 10.40.72.1 (10.40.72.1) 96.114 ms 96.044 ms 96.294 ms
5 10.40.73.33 (10.40.73.33) 99.350 ms 96.353 ms 99.129 ms
6 * * *
7 10.40.69.65 (10.40.69.65) 66.813 ms 66.721 ms 65.910 ms
8 10.40.69.98 (10.40.69.98) 64.090 ms 64.000 ms 63.533 ms
9 10.0.11.169 (10.0.11.169) 63.457 ms 62.483 ms 62.386 ms
10 10.0.77.20 (10.0.77.20) 62.013 ms 79.632 ms 79.657 ms
11 10.0.77.1 (10.0.77.1) 83.412 ms 82.312 ms 82.575 ms
12 10.0.72.34 (10.0.72.34) 84.991 ms 84.919 ms 79.934 ms
13 10.0.77.118 (10.0.77.118) 79.811 ms 79.429 ms 103.539 ms
14 10.0.77.110 (10.0.77.110) 83.904 ms 82.089 ms 80.381 ms
15 10.21.252.246 (10.21.252.246) 80.417 ms 80.624 ms 80.545 ms
16 10.21.71.20 (10.21.71.20) 91.927 ms 89.772 ms 89.220 ms
17 10.21.71.20 (10.21.71.20) 92.004 ms 91.606 ms 91.540 ms
18 ix-et-4-0-5-0.tcore1.fnm-frankfurt.as6453.net (195.219.156.148) 207.375 ms 10.21.0.21 (10.21.0.21) 92.005 ms 90.894 ms
19 10.21.0.21 (10.21.0.21) 80.345 ms if-ae-9-2.tcore2.fr0-frankfurt.as6453.net (5.23.30.17) 196.298 ms 196.007 ms
20 if-ae-45-2.tcore1.fr0-frankfurt.as6453.net (195.219.50.20) 188.921 ms 195.807 ms et-5-0-0-0.ffttr6.-.opentransit.net (193.251.154.103) 168.200 Ms
21 72.14.214.52 (72.14.214.52) 167.552 ms google-13.gw.opentransit.net (193.251.252.246) 167.360 ms *
22 108.170.251.129 (108.170.251.129) 175.274 ms * 135.098 ms
23 * 72.14.232.33 (72.14.232.33) 134.970 ms dns.google (8.8.8.8) 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.