Skip to content

Linux Network Interface

A network interface controller (NIC, also known as a network interface card network adapter, LAN adapter or physical network interface, and by similar terms) is a computer hardware component that connects a computer to a computer network. More on wikipedia.

Imagine them as the little gizmos inside your computer that let it chat with the internet or any other network. Think of a NIC like a computer's networking buddy, helping it get online, whether it's through cables or Wi-Fi waves.

These NICs are pretty smart. They handle all sorts of networking tasks – making sure data goes where it's supposed to, dealing with internet traffic like a pro, and even splitting up data to send it off in different directions. They're like the post office of your computer, sorting and sending your data packets to the right place.

NICs are the go-betweens for your computer and the big wide web. Say you're itching to see the latest viral cat video. Your computer tells the NIC, "Hey, I need to see this," and the NIC turns that request into signals that zoom across the internet. The web server with your video gets the message, sends the video back as more signals, and your NIC translates those back into the video you see on your screen.

Back in the day, NICs were like extra cards you'd plug into your computer. But now, they're often built right into the motherboard, making it easier to connect to the internet without extra fuss. If you need more connections or something special, though, you can still grab a NIC that suits your fancy from your favourite radioshak store 🤓.

And yes, people might call NICs by other names like network interface controller, network adapter, network cards, or LAN adapter, but they're all talking about the same thing.

NICs Come in Different Flavors

  • Wireless NICs: These are the freedom lovers, connecting you to Wi-Fi without any cables. Perfect for browsing in bed or at the coffee shop.
  • Wired NICs: Old reliable. These need cables to connect but offer solid, speedy connections. Ethernet cables are their best buds.
  • USB NICs: Handy for when you need to plug in a quick network connection through a USB port.
  • Fiber Optics NICs: The speed demons, used for super-fast connections, usually in big server setups or when you really, really can't stand buffering.

What Makes NICs Tick

  • Speed: Measured in Mbps or Gbps, this tells you how fast the NIC can send or receive data. Just remember, the speed of your network can affect this too.
  • Driver: This software makes sure your NIC and computer play nice, allowing them to communicate properly.
  • MAC Address: Every NIC has a unique MAC address, like a fingerprint, ensuring data packets find their way to your computer and not someone else's.
  • LED Indicator: Those little blinking lights on the NIC aren't just for show. They tell you if you're connected and if data's moving. Generaly when you see a green light and an other blink your are good 😎
  • Router Connection: Sometimes, your NIC talks to a router, which then connects you to the wider internet, especially in Wi-Fi setups.

So there you have it, a little summary about NICs. Knowing how these bad boys work and how to pick the right one can make a big difference in your internet experience, whether you're gaming, streaming, or just surfing the web. Now let's explore some commands !

Display list of network cards

You can use any one of the following command to list network cards installed under Linux operating systems. Please note that the ifconfig and ip commands will also display interfaces information about vpn, loopback, and other configured interfaces.

Linux systems use two different styles of naming the network interfaces. The first style is the old-style name, such as eth0, eth1, and wlan0. The new ones are based on hardware locations like enp6s0 and wlp2s0. To print them just run :

ls /sys/class/net

You should get something like this in output :

docker0  enp6s0  lo  veth6bf6102  vmnet1  vmnet8

To get more details about the network interfaces. we can use the ip link command

ifconfig command

ifconfig (short for interface config) is a system administration utility in Unix-like operating systems for network interface configuration.

The utility is a command-line interface tool and is also used in the system startup scripts of many operating systems. It has features for configuring, controlling, and querying TCP/IP network interface parameters. More on wikipedia

At its most basic, running ifconfig without any arguments displays the current configuration for all active network interfaces on the system. This includes information like the IP address, subnet mask, broadcast address, MAC (Media Access Control) address, and other data related to each network interface.

ifconfig

Specific Interface

You can specify an interface name to view or configure just that interface. For example, to see details about the eth0 interface, you would use:

ifconfig eth0

Assigning IP Address and Netmask

To configure an IP address and subnet mask for an interface, you can use ifconfig followed by the interface name, the IP address, and the netmask. For example, to set the IP address of eth0 to 192.168.1.2 with a subnet mask of 255.255.255.0, you would use:

sudo ifconfig eth0 192.168.1.2 netmask 255.255.255.0

Changing the MAC Address

If you really know what you are doing ifconfig allows you to change the MAC address of an interface, which can be useful for network testing or privacy reasons.

sudo ifconfig eth0 hw ether 02:01:02:03:04:08

This command sets the MAC address of eth0 to 02:01:02:03:04:08.

Viewing All Interfaces

To view both active and inactive interfaces, you might need to use the -a flag, although the behavior can differ between Linux distributions and versions of ifconfig:

ifconfig -a

lspci command

Use lspci command Linux command to show list of network cards Type the following lspci command along with egrep command to filter out devices:

lspci | egrep -i --color 'network|ethernet'
lspci | egrep -i --color 'network|ethernet|wireless|wi-fi'

You should have this ind of output :

06:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8125 2.5GbE Controller (rev 05)
0c:00.0 Network controller: Intel Corporation Ultimate N WiFi Link 5300

lshw command

The lshw command can extract detailed information on the hardware configuration of the machine including network cards. Type the following command:

lshw -class network

By default, lshw or hwinfo command may not be installed on your system. Hence, use the apk command on Alpine Linux, dnf command/yum command on RHEL & co, apt command/apt-get command on Debian, Ubuntu & co

This command will display many information I recommand his cousin lshw -class network -short, it will show something like this :

H/W path           Device        Class          Description
===========================================================
/0/100/1d.6/0      enp6s0       network         RTL8125 2.5GbE Controller
/0/100/1f.6        eth0          network        Ethernet Connection (7) I219-LM

WARNING: output may be incomplete or inaccurate, you should run this program as super-user.
The -class network view all network cards on your Linux system and the -short will display a device tree showing hardware paths.
Note

You can use the device to show some ip and networks informations with the command ip a show enp6s0

The /proc/net/dev file

The dev pseudo-file contains network device status information. This gives the number of received and sent packets, the number of errors and collisions and other basic statistics.

In other term, /etc/network/interfaces file is a way to configure network interfaces. The majority of the network setup can be done via this file. We can give an IP address to a network interface either statically or dynamically. Further, we can set up routing information, a DNS server, etc.

Moreover, when we use the network interface management commands, they bring up and down the interfaces and configure them based on the /etc/network/interfaces file: the ifup command brings the network interface up, while the ifdown command takes it down.

Open the terminal and then type the following command :

cat /proc/net/dev

You should see something like this :

Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo: 8018040716 30374762    0    0    0     0          0         0 8018040716 30374762    0    0    0     0       0          0
enp6s0: 30340928099 25426754    0    0    0     0          0    121557 5200660099 7306821    0    0    0     0       0          0
docker0: 22072940  156650    0    0    0     0          0         0 260292467  141390    0    0    0     0       0          0
vmnet1:       0       0    0    0    0     0          0         0        0     596    0    0    0     0       0          0
vmnet8:       0       0    0    0    0     0          0         0        0     595    0    0    0     0       0          0
veth6bf6102: 24266040  156650    0    0    0     0          0         0 260327790  141779    0    0    0     0       0          0

You can notice that I have some other networking interface vmnet and docker0 for example. This is because I have VM Ware virtual machines running on my machine and docker, these two softwares need network connection, so they have their own network virtual cards and we can see them 😎

🚧 Enabling and Disabling Network Interfaces 🚧

To manually activate or deactivate a network interface, we use ifup/ifdown commands. Be carful with this command do not run them if you do not know what you are doing please !

In order to enable the interface docker0, for example, we do:

sudo ifup docker0
In the same way, we can disable the network interface of docker :
sudo ifdown docker0
Note

If you want to know mnore about the network interface and how to configure your own network interface with a proper syntax

Become a network interface ninja

Linux has rich virtual networking capabilities that are used as basis for hosting VMs and containers, as well as cloud environments. I recommend you these articles :

Wrap it up

We learned about various Linux commands to display information about installed and running network cards.

Now you know that docker and vmware are emulate their own virtual networking card to do their stuff (we do not need to go into many details here, we trust them lol).

Keep in mind that if you are not a networking engineer you probally do not need to go deep into details about this, but you know it always cool to interact with our machine 😇