Your ubuntu server has lost network connection?

Sergi Rodríguez  
17-01-2021 15:56  
5 minutos de lectura  

I'm not an specialist on this area, but a novel sysadmin i had to solve this situation and it took to me almost 10 hours (2 days) to get it well solved. I want to share what i learned with you. I need to express my thanks to the great customer support team at clouding.io (my BEST cloud hosting provider).

How to check if your server has network connection

The only way to be sure is to use the "emergency console" from the provider website (previously logged as customer). You can connect through SSH because the server cannot reach public network!

Once logged (usuarlly as root user) run a simple:

ping 8.8.8.8

If there is not network connection you will see a message saying this. If there is network connection you will see something like this:

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=119 time=8.83 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=119 time=8.93 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=119 time=8.86 ms

Note: Can be several causes for network connection missconfiguration. For example, an update of the server you executed could ask you to maintain or replace the existing configuration file of the GRUB, and if you choose "Y" to replace then it probably broke your network configuration, specially the names of the interfaces.

Next step: which is my "ethernet" interface NAME

Then run this command:

ifconfig -a

Note: it's very important the option "-a" because then the output will include also the missconfigured network interfaces.

You will see a list of blocks of information (several lines), a block per network interface. You must allocate the one of type "Ethernet" which no has an IP (v.4) address defined. Like this:

ens3      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 MB)  TX bytes:0 (0.0 MB)

In my case the name is ens3, but it could use ens2, eth0, eth1, ... so you must allocate yours own.

Next step: define DCHP for that network interface

The reason that your server has not connection is that this interface has not been configured. The easiest and most usual way to do it is through DHCP (you know: another machine assign a LAN IP to your server).

We can get it instantly running this command:

dhclient ens3

Simple, eh!? But when you reboot machine (for example after an upgrade of the linux kernel) this network interface will became again missconfigured. So you need a permanent setting.

It's very easy: edit this file (or add if it is missing)

/etc/network/interfaces.d/ens3.cfg

obviously replacing the "ens3" by the name of your network interface, and adding these 2 lines:

allow-hotplug ens3
iface ens3 inet dhcp

So simple, and so powerful!

You should also check that this file:

/etc/network/interfaces

contain something like this:

source /etc/network/interfaces.d/*.cfg

I'm not a veteran sysadmin, but i would say that it is required.

Check settings once rebooted

Run the command sudo reboot now to reboot the machine, and once rebooted probably your server will hace again network connection.

If you then run ifconfig -a again will see that the network interface has already an IP assigned:

ens3      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          inet addr:185.xxx.xxx.xxx  Bcast:185.xxx.xxx.xxx  Mask:255.255.254.0
          inet6 addr: fe80::f816:xxxx:xxxx:xxxx/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:100939 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8104 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:6890645 (6.8 MB)  TX bytes:2677288 (2.6 MB)

Etiquetas : network | server | linux | hosting

Comentarios 0   Visitas 2664  

  Comentarios


Añada su comentario:

Comentario:
Nombre:
(pregunta anti-robots)

Enviar

DÍGANOS QUÉ NECESITA

¡¡ Le respondemos antes de 24h !!
Puede dejarnos su teléfono.

Puede rellenar el formulario (pulsar botón derecha) o bien aquí tiene nuestros datos de contacto.

(pregunta anti-robots)

  Enviar

Revisar consentimientos a cookies