Understanding and managing network interfaces is an essential skill for any Linux system administrator. In this comprehensive guide, we will explore the various methods and commands for listing, configuring, and troubleshooting network interfaces in Ubuntu.

An Introduction to Network Interfaces

A network interface refers to the software interface that allows a device to connect to a computer network. It enables communicating and transferring data between different nodes in a network.

There are two main types of network interfaces in Linux systems:

Physical Network Interfaces: These correspond to the actual hardware network adapters like ethernet, Wi-Fi, or modem cards. Some examples are eth0, wlan0, etc.

Virtual Network Interfaces: These are logical software interfaces not tied to any hardware device. Examples include bridges, bonds, VLANs, loopbacks, etc.

Network interfaces in Ubuntu and Linux can be managed via various terminal commands and configuration files. As an administrator, being able to view, set up, and troubleshoot interfaces is a crucial skill.

Let‘s go through the key commands for that:

1. ip Command for Network Interface Management

The ip command is used to show and manipulate routing, devices, policy routing, and tunnels in Linux. For network interfaces, some useful ip commands are:

List All Interfaces

To list all network interfaces in Ubuntu, use:

ip link show

This gives output like:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:8b:c9:3f brd ff:ff:ff:ff:ff:ff

This shows the loopback interface lo and ethernet interface eth0 along with properties like link status, MAC address, MTU size etc.

Show Interface Addresses

To view addresses assigned to interfaces:

ip addr show

Sample output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:8b:c9:3f brd ff:ff:ff:ff:ff:ff
    inet 10.20.30.40/24 brd 10.20.30.255 scope global dynamic eth0
       valid_lft 85865sec preferred_lft 85865sec

Here you can see the IP address 10.20.30.40 assigned to eth0.

Enable/Disable an Interface

To enable or disable an interface like eth0:

ip link set eth0 up/down

Verify with:

ip link show eth0

Add/Delete IP Addresses

Adding an IP 192.168.1.10/24 to interface eth1:

ip addr add 192.168.1.10/24 dev eth1

Delete it using:

ip addr del 192.168.1.10/24 dev eth1

The ip command is very flexible for viewing and modifying many aspects of network interfaces from the command line.

2. ifconfig for Interface Administration

The ifconfig command has been used traditionally to view and configure network interfaces in Linux. Its popularity has reduced after ip came out, but still used frequently by sysadmins.

To use ifconfig for managing interfaces in Ubuntu:

Show All Interfaces

List all interfaces with:

ifconfig -a

Typical output:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.20.30.40  netmask 255.255.255.0  broadcast 10.20.30.255
        inet6 fe80::a00:27ff:fe8b:c93f  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:8b:c93f  txqueuelen 1000  (Ethernet)
        RX packets 4457220  bytes 6432132148 (6.4 GB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3223251  bytes 418045224 (418.0 MB)
        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 8132  bytes 650152 (650.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8132  bytes 650152 (650.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

This displays all interfaces present including information like IP address, MAC address, MTU size, received/transmitted packets etc.

Enable or Disable an Interface

To disable eth0:

ifconfig eth0 down

Enable it again:

ifconfig eth0 up

Change IP Address

Change IP address of eth0 to 192.168.1.10:

ifconfig eth0 192.168.1.10 netmask 255.255.255.0

Similar to the ip command, ifconfig can be used to view current network interface information and bring interfaces up/down as needed.

3. nmcli Tool for NetworkManager Interfaces

NetworkManager is a service in Linux responsible for network interface management and auto-configuration. The nmcli command is a powerful tool that allows interfacing with NetworkManager from the CLI.

Some examples with nmcli:

Listing Interfaces Managed by NetworkManager

nmcli device status

Sample output:

DEVICE  TYPE      STATE      CONNECTION 
eth0    ethernet  connected  Wired connection 1    
wlan0   wifi      disconnected  --
lo      loopback  unmanaged  --

This shows devices that are being handled by NetworkManager.

Display Detailed Profile Information

Get detailed information on connections with:

nmcli connection show

Example output:

NAME                UUID                                  TYPE      DEVICE  
Wired connection 1  3dadf26f-6a8d-3b28-967a-a6e13553912f  ethernet  eth0

The connection profile name, uuid, type and interface name associated is shown here.

Activate/Deactivate Interfaces

Say we have a profile called my-eth1 for interface eth1. To activate:

nmcli con up my-eth1

Deactivate it with:

nmcli con down my-eth1 

The nmcli command gives full access to controlling NetworkManager behavior via the CLI, which is very helpful in interface management.

4. Using the /sys Filesystem

The Linux /sys filesystem contains information about system devices and drivers. Network interface properties can also be accessed from /sys/class/net/

List Interface Names

Running a simple ls shows all current interfaces:

$ ls /sys/class/net/
eth0  lo  wlan0

There will be a folder for each interface present.

Interface Details

Navigating inside an interface folder provides more data. For example, eth0 MAC address:

$ cat /sys/class/net/eth0/address  
08:00:27:0b:56:10

The eth0 subfolder contains various statistics like number of received packets, bytes transferred, errors etc.

This allows querying useful per-interface information programmatically.

5. ethtool for Diagnostics

The ethtool command is another option for getting network interface configurations and diagnostics.

Running ethtool followed by the interface name displays extensive low-level information.

For instance, getting capabilities of interface eth1:

$ ethtool eth1

Settings for eth1:
        Supported ports: [ TP ]
        Supported link modes: 10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Supported pause frame use: No
        Supports auto-negotiation: Yes
        Supported FEC modes: Not reported
        Advertised link modes: 10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Speed: 100Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: Unknown
        Supports Wake-on: pumbg
        Wake-on: g
        Current message level: 0x000000ff (255)
                               drv probe link timer ifdown ifup rx_err tx_err rx tx
        Link detected: yes

This shows port type, speeds supported, auto-negotiation status, wake-on settings etc. related to the eth1 interface.

6. Monitoring with netstat

The netstat command displays various network statistics and connections in Linux.

To continually monitor network interface packet rates:

watch -n1 netstat -i

It will refresh values per second:

Every 1.0s: netstat -i                       Mon Feb 20 05:21:34 2023

Kernel Interface table
Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0      1500  821107      0 0         0  1054643      0      0 0         BRU 
lo       65536   27060      0 0         0   27060      0      0 0         LR

Values like received/sent packets, errors etc. can be checked this way to detect issues.

Key Files for Network Interface Configuration

Ubuntu and Linux represent interfaces through control and configuration files as well:

  • /etc/network/interfaces: This file is used to define all non-temporary interfaces with options like IP address, netmask, gateway etc.

  • */etc/netplan/.yaml:** Ubuntu uses netplan YAML files like 01-netcfg.yaml to configure interfaces and networking.

  • ifcfg- files: Configuration of individual interfaces is stored in files like /etc/sysconfig/network-scripts/ifcfg-eth0 with that interface‘s attributes.

  • Systemd .link files: For managing virtual interfaces like bonds/bridges, .link files are created in /etc/systemd/network/ defining them.

The correct files will need editing to make permanent interface changes persist across boots instead of just runtime terminal tweaks.

Troubleshooting Interface Issues

Some things to try out if facing network interface problems in Ubuntu:

  • Run ip link show and ifconfig -a to check for missing interfaces or unusual statuses. Verify Ethernet links/cables if any interface is missing.

  • Reconnect cables, restart networking services with systemctl restart networking, or reboot to attempt fixing transient hardware issues.

  • For receiving/transmitting packet losses, analyze interface counters in /sys, check routes with ip route show, inspect applications consuming bandwidth with tools like nethogs.

  • Enable kernel debug logs temporarily using sysctl -w net.core.message_cost=1. Then check output of dmesg for driver errors after reproducing the problem.

  • For virtual interfaces like bonds not appearing correctly, ensure .link files in /etc/systemd/network/ define them appropriately so they persist after reboot.

There can be many root causes for network interface glitches depending on OS version and hardware specifics. But methodically following standard Linux troubleshooting practices helps identify and rectify them.

Conclusion

Managing network interfaces is an integral duty of Linux system administrators for ensuring availability and performance of critical network communications.

We explored the essential terminal utilities like ip, ifconfig, nmcli for interface administration in Ubuntu. Monitoring bandwidth usage with netstat and diagnosing issues using ethtool, dmesg etc. was also covered. Additionally, the core configuration files to be aware of were highlighted.

With this extensive guide on viewing, configuring and troubleshooting interfaces via various methods, you should now feel confident to handle interface-related tasks in Ubuntu. Let me know if you have any other favorite network admin tools or techniques!

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *