June 3, 2020

Impact & Learning

Learn to impact

Network interfaces configuration in Linux

Read Time:3 Minute, 12 Second

In this tutorial, I will show how to create or modify a Network interface configuration in Linux. This procedure is essential to know the network interface through which we connect to the internet or local network, as well as its connection and configuration for a new connection to the network.

Configure a network interface

The configuration of network interfaces is essential for their identification and use by the network. Before proceeding with the configuration, it is important to learn to identify our existing network interfaces on the system, as well as their corresponding IP address.

The command to display the network interfaces as well as their IP addresses is the follow:

root@linus:~# ip address show

1: lo: mtu 17486 qdisc noqueue
     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
     inet 127.0.0.1/8 scope host lo
     inet6 ::1/128 scope host
        valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
     link/ether 00:0d:18:b2:b3:89 brd ff:ff:ff:ff:ff:ff
     inet 192.168.1.14/24 brd 192.168.1.255 scope global eth0
     inet 10.0.0.10/8 brd 10.255.255.255 scope global eth0:0
     inet 10.0.0.20/8 brd 10.255.255.255 scope global secondary eth0:1
     inet6 fe80::25c6:9e7:8271:b411/64 scope link
        valid_lft forever preferred_lft forever

We have two network interfaces, the first one (lo) is our localhost whose address 127.0.0.1 and this only has local scope towards the device. The eth0 interface is a network interface connected by cable (ethernet), which in this example has the ip address 192.168.1.14.

There are also other options for displaying network interfaces, for example using the ifconfig command. With the ip utility To configure a network interface in Linux, it is possible to do it using the following command:

ip address add 10.0.0.11/16 dev eth0 

With this command, we add the ip address 10.0.0.11, which has a 16-bit netmask. This means that we can have 16 bits of different IP addresses for our local network, which in network terms is represented as 255.255.0.0 (/ 16). We assign this ip address to the eth0 interface.

Network configuration with ifconfig

If you want to use the ifconfig command, the network configuration is done through the following command:

ifconfig eth0 192.168.1.5 netmask 255.255.255.0 broadcast 192.168.1.255 

Here the assignment of the ip 192.168.1.5 is for the eth0 interface, a 24-bit netmask is established (255.255.255.0, or / 24) and the broadcast is made to the replicator or modem (gateway) located with the ip 192.168.1.255.

Virtual interface configuration

In real network interfaces, each interface can store an IP address (version 4) for identification of the equipment or device, however, thanks to virtual interfaces, we can assign several interfaces within a single interface, each with its respective ip.

For the assignment of virtual addresses, we make use of the ifconfig command and indicate the network interfaces numerically as follows:

ifconfig eth0:0 192.168.1.12 
ifconfig eth0:1 192.168.1.13 

In the example above, we configure two virtual interfaces within the real eth0 interface, which respond to the name eth0:0 and eth0:1 respectively. They also have their own IP address.

Other interesting topics

We recommend you follow us and read these Linux tutorials:

Task automation in Linux with Crontab
Adding users, groups and superusers in Linux
Introduction to Git
1 0
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleppy
Sleppy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %