Network Interfaces in Linux

Nilesh Katuwal Jan 30, 2023
  1. the Physical and Virtual Network Interface in Linux
  2. Use the ifconfig Command to Diagnose and Configure Network Interfaces in Linux
  3. Setting Up eth0 in Linux
  4. the Interface Setup to dhcp in Linux
  5. Editing the /etc/network/interfaces File to Create a static Address Interface
Network Interfaces in Linux

This tutorial will look at the full syntax explanation in /etc/network/interfaces in Debian and its derivative editions.

The file /etc/network/interfaces lets you specify static and dynamic IP addresses for interfaces configure routing information, default gateways, disguise network bonding, and more.

the Physical and Virtual Network Interface in Linux

A TCP/IP implementation defines an interface that disguises network provisioning variations and reduces network communication to data exchange with an abstract entity.

The Linux kernel distinguishes between physical and virtual network interfaces.

Use the ifconfig Command to Diagnose and Configure Network Interfaces in Linux

The ifconfig is a UNIX-like system command-line program for diagnosing and configuring network interfaces.

$ ifconfig

Output:

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:72:4e:1a:db  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp3s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether d4:81:d7:bd:c6:ef  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 11182  bytes 1139133 (1.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 11182  bytes 1139133 (1.1 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.69  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 2403:3800:3217:204b:3be8:d506:7950:933c  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::4cd5:8a62:8187:55fc  prefixlen 64  scopeid 0x20<link>
        inet6 2403:3800:3217:204b:9902:5eba:d521:1d6b  prefixlen 64  scopeid 0x0<global>
        ether 3c:f8:62:e5:d7:e2  txqueuelen 1000  (Ethernet)
        RX packets 521763  bytes 557860095 (557.8 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 288568  bytes 61590689 (61.5 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

We can see that there are four network interfaces.

  • The docker0 is a docker’s virtual bridge interface that establishes a distinct network for Docker containers, allowing them to connect.
  • The enp3s0 is previously known as eth0. This physical interface represents an Ethernet network.
  • The lo is a virtual network interface primarily used for diagnostics and troubleshooting and connects to services operating on the localhost.
  • The wlp2so is your wifi interface.

Setting Up eth0 in Linux

Set up eth0 (initial network interface card) with 192.168.1.5 IP address and a gateway (router) to 192.168.1.254 in the following example:

iface eth0 inet static
address 192.168.1.5
netmask 255.255.255.0
gateway 192.168.1.254

the Interface Setup to dhcp in Linux

Use the following command to eth0 to dhcp.

auto eth0
iface eth0 inet dhcp

Editing the /etc/network/interfaces File to Create a static Address Interface

If you want to configure a static IP address and gateway instead of using DHCP, replace the previous instructions with the following (change 192.168.0.8/24 and 192.168.0.1 with your actual IP addresses):

auto <Interface>
iface <Interface> inet static
address 192.168.0.1
netmask 255.255.255.0

gateway 192.168.0.1
dns-nameservers 8.8.8.8