Tabla de contenido
Hello! I recently had some problems with a network card. That made me realize that it would be a good idea to upload an article on the subject. Today I am going to show 4 points to take into account when configuring a network interface in linux.
Please, if you like this kind of content share it on your social networks and/or comment.
Let’s get started!
1. We have no network in the system
As a general rule, running ip a show or ip a should display the list of interfaces (in older distributions this is done with ifconfig):
If everything goes well and we simply do not have the IP configured we can configure it as follows (this way of configuring it will only work as long as we do not restart the network service and reboot the system):
With ip a a xxx.xxx.xxx.xxx.xxx.xxx/mask dev ethX we add a new IP to the network interface, it is important to define the IP mask correctly because if none is specified it adds a /32 by default and we will not be able to configure the routes.
As you can see in the image we must also add the default route so that we use the correct gateway, in this case 192.168.1.1. It is a good habit to make two pings before configuring an IP, a ping to another IP of the network and another ping to the internet (if it is a device that must have an output to the internet). The default route can be added with ip route a default via IP_GATEWAY dev ethX as shown in the image.
2. We have configured the interface and we are still without network
As you can see in the image we still cannot resolve names. It is necessary to be careful since in many cases we can believe that we do not have network and simply we are not able to resolve names. To get out of doubt with a simple ping to a public ip as for example 8.8.8.8.8 we would be able to know if we are really going out to the internet or not.
In this case as we have already done it before we are going to configure the DNS server that we are going to use and we are going to repeat the operation:
Once the DNS has been configured, everything is working correctly.
3. We have had network configured but when making any change it does not work.
When we clone a virtual machine or change a network card (even if we replace it with the same model) the network may not work correctly. This may be due to the fact that we have stored the mac of the device in the file 70-persistent-net.rules (/etc/udev/rules.d/70-persistent-net.rules) related to the device for which we have configuration.
The main symptom of this is that when we run ip a we will see the interface with another name. For example if we only have one network card and the card should be called eth0 it will be called eth1:
Para solucionar esto, solo se tiene que eliminar el fichero /etc/udev/rules.d/70-persistent-net.rules o también se puede editar el fichero y borrar la linea que nos “molesta”, por ejemplo este es un ejemplo de “eth0”
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:26:b9:82:21:7a”, ATTR{dev_id}==”0x0″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″
I recommend deleting the file. Then we only have to reboot the system and the network should work correctly if we have the network configured correctly and the interfaces are called as they should be.
4. When no interfaces appear withip a
It is possible that when trying to configure the network of a system we find that with ip a we are not recognizing the interface to configure this is an indicator that it is possible that we do not have the kernel module for this network card, this kernel module would be the equivalent to a windows driver (this clarification goes for the newcomers of windows).
To check if this happens, we can run ls /sys/class/net as shown below:
ger@portatil:~$ ls -al /sys/class/net/
total 0
drwxr-xr-x 2 root root 0 nov 18 21:52 .
drwxr-xr-x 67 root root 0 nov 18 21:52 ..
lrwxrwxrwx 1 root root 0 nov 18 21:52 docker0 -> ../../devices/virtual/net/docker0
lrwxrwxrwx 1 root root 0 nov 18 21:52 enp1s0f0 -> ../../devices/pci0000:00/0000:00:02.2/0000:01:00.0/net/enp1s0f0
lrwxrwxrwx 1 root root 0 nov 18 21:52 lo -> ../../devices/virtual/net/lo
lrwxrwxrwx 1 root root 0 nov 18 21:52 tun0 -> ../../devices/virtual/net/tun0
lrwxrwxrwx 1 root root 0 nov 18 21:52 veth019ec36 -> ../../devices/virtual/net/veth019ec36
lrwxrwxrwx 1 root root 0 nov 18 21:52 wlp5s0 -> ../../devices/pci0000:00/0000:00:02.3/0000:05:00.0/net/wlp5s0
With this command we must see all the interfaces that the system has. If we do not see any of them the next step is to check if we see the device with lspci o con lsusb depending on whether the device is USB or PCI:
ger@portatil:~$ lspci|grep -i net
01:00.0 Ethernet controller: Qualcomm Atheros QCA8171 Gigabit Ethernet (rev 13)
05:00.0 Network controller: Qualcomm Atheros QCA9565 / AR9565 Wireless Network Adapter (rev 01)
ger@portatil:~$ lsusb|grep -i net
ger@portatil:~$
If the device appears in the list of recognized devices but does not appear when you run ip anor when executing ls /sys/clases/net we must check if the kernel modules correspond to the loaded kernel:
[root@localhost ~]# ls -al /lib/modules/
total 8
drwxr-xr-x. 3 root root 35 nov 18 21:36 .
dr-xr-xr-x. 27 root root 4096 oct 19 20:38 ..
drwxr-xr-x. 7 root root 4096 oct 19 20:41 3.10.0-862.el7.x86_64
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]#
If the kernel modules were missing we would have to get them (sometimes just copying the directory of another kernel version to the current kernel works all the modules correctly). In this case everything is OK so we should install the missing PCI or USB interface kernel module. Normally this module can be downloaded from the manufacturer’s website.
This has been all about the 4 points to take into account when configuring a network interface in linux, if you liked the article we appreciate if you share it on your social networks and / or comment.
See you soon!