Linux online course

Linux ifconfig Command: View and Configure Network Interfaces

Learn how to use Linux ifconfig to inspect interfaces, view IPv4 settings, assign a temporary address and netmask, and enable or disable interfaces safely.

ifconfig is a Linux network-interface utility. It displays and changes settings for network interfaces such as Ethernet adapters, Wi-Fi devices, loopback, and virtual adapters.

With ifconfig, you can inspect interface names, IPv4 addresses, subnet masks, MAC addresses, status flags, and traffic counters. With administrative privileges, you can temporarily assign an IPv4 address or bring an interface up or down.

Availability and the Modern Linux Context

On many distributions, ifconfig is supplied by the net-tools package. It may not be installed by default, especially on newer systems. If the shell reports that the command is missing, install the distribution package that provides net-tools if you specifically need legacy compatibility.

The modern replacement is the ip command, supplied by iproute2. This lesson focuses on ifconfig, but current Linux administration generally uses commands such as ip addr show and ip link show.

Prerequisites and Key Terms

  • A network interface is the software representation of a connection, such as Ethernet, Wi-Fi, loopback, or a virtual adapter.
  • An IPv4 address is a 32-bit address written in dotted-decimal form, such as 5.5.5.5.
  • A subnet mask, or netmask, identifies which part of an IPv4 address represents the local network. 255.255.255.0 is also written as the CIDR prefix /24.
  • A MAC address is a link-layer address associated with a network adapter.
  • The default gateway is the router used to reach destinations outside the local network.
  • DNS, the Domain Name System, translates hostnames such as names into IP addresses. DNS configuration is separate from ifconfig.

Display All Active Interfaces

Run ifconfig with no arguments:

ifconfig

This commonly lists active interfaces and their network settings. A normal unprivileged user can usually inspect this information. Changing an address or interface state normally requires sudo or another form of elevated privilege.

Field or conceptMeaningWhy it matters
Interface nameThe local name assigned to the interface, such as eth0, enp0s3, or lo.Commands must target the correct interface.
IPv4 addressThe interface's IPv4 address.Identifies the host on an IPv4 network.
NetmaskThe IPv4 subnet mask, such as 255.255.255.0.Determines which destinations are local.
Broadcast addressAn address used to reach all hosts on a local broadcast network.Helps verify the address and subnet configuration.
MAC/HWaddrThe adapter's link-layer hardware address.Useful for identifying adapters and diagnosing local-network issues.
Flags or stateStatus indicators showing conditions such as up, running, or broadcast-capable.Helps determine whether the interface is active.
MTUMaximum Transmission Unit: the largest packet size normally sent without fragmentation.Unusual MTU values can affect connectivity.
RX/TX packet countersReceive and transmit packet and byte statistics.Useful for checking whether traffic is arriving or leaving.

Understanding Interface Names and Types

Interface names vary by system. Older installations often use names such as eth0 for the first Ethernet adapter. Newer Linux systems commonly use predictable names such as enp0s3, ens33, or eno1. Do not assume that eth0 exists.

The interface named lo is the loopback interface. It allows programs on a host to communicate with the same host without sending traffic through a physical adapter. The loopback IPv4 address is commonly 127.0.0.1.

  • Physical Ethernet: commonly named eth0, eno1, or similar.
  • Wi-Fi: often has a name beginning with w, although exact naming varies.
  • Virtual interfaces: created by software, containers, virtual machines, bridges, tunnels, or other networking features.
  • Loopback: the local-only lo interface.

Display One Interface

When a system has several adapters, request one named interface:

ifconfig eth0

This narrows the output to eth0. Replace eth0 with the actual name on the local system. The name can be found with ifconfig -a or ip link show.

Assign an IPv4 Address and Subnet Mask

The basic ifconfig form for assigning an IPv4 address is:

sudo ifconfig <interface> <IPv4-address> netmask <netmask>

For example:

sudo ifconfig eth0 5.5.5.5 netmask 255.255.255.0

This assigns 5.5.5.5 to eth0 with the netmask 255.255.255.0. That mask corresponds to a /24 CIDR network because 24 of the 32 IPv4 bits identify the network portion.

Assigning an address alone does not guarantee external connectivity. A usable connection may also require:

  • A working physical or wireless link.
  • A suitable route and default gateway.
  • Correct VLAN or upstream network settings.
  • Firewall rules that permit the traffic.
  • DNS servers for hostname resolution.

ifconfig configures the interface address; it does not configure DNS and does not by itself create a persistent static-IP configuration.

Enable and Disable an Interface

Bring an interface down with:

sudo ifconfig eth0 down

Taking an interface down disables network connectivity through that interface. Any SSH session using it can be disconnected.

Bring it up with:

sudo ifconfig eth0 up

Bringing an interface up only enables the interface. It may still need an IPv4 address, a route, a DHCP configuration, or other network settings before it can communicate.

View Inactive Interfaces

Plain ifconfig may omit interfaces that are down or otherwise inactive. Use the -a option to display all detected interfaces:

ifconfig -a

This is useful after disabling an interface and when troubleshooting an adapter that does not appear in ordinary output.

Common ifconfig Commands

CommandPurposeNotes
ifconfigShow active interfaces and their settings.Usually readable without elevated privileges.
ifconfig -aShow active and inactive interfaces.Useful for detecting a down or missing adapter.
ifconfig <interface>Show one named interface.Replace the placeholder with a locally detected name.
sudo ifconfig <interface> <IPv4-address> netmask <netmask>Assign an IPv4 address and subnet mask.Runtime change; use a valid, non-conflicting network address.
sudo ifconfig <interface> upEnable an interface.Does not automatically provide a route, address, or DNS.
sudo ifconfig <interface> downDisable an interface.Stops connectivity through that interface.

ifconfig and Modern Linux Networking Tools

Taskifconfig approachModern approachPersistence consideration
View addressesifconfigip addr showBoth are primarily inspection commands.
View all interfacesifconfig -aip link show or ip addr showThese display runtime state, not a persistent configuration.
Set an addresssudo ifconfig <interface> <address> netmask <mask>Use the appropriate ip addr syntax.Configure the distribution's network-management system for persistence.
Bring an interface up or downsudo ifconfig <interface> up|downUse the appropriate ip link syntax.A network manager may later change the runtime state.
Configure DNSNot provided by ifconfig.Use the active resolver or network-management system.DNS belongs in persistent resolver or network configuration.
Create persistent configurationNot provided by ifconfig.Use NetworkManager, netplan, systemd-networkd, or the distribution's equivalent.Persistent setup must be managed outside ifconfig.

Privilege and Remote-System Safety

  • Use sudo for commands that change an address or interface state.
  • Confirm the interface name and current address before changing anything.
  • Changing the interface carrying an SSH connection can immediately disconnect the remote session.
  • For risky changes, use console access or prepare a safe rollback plan.
  • Use ifconfig for temporary testing or legacy systems, not as the primary method for persistent network administration.

Troubleshooting ifconfig

ifconfig is not found

The net-tools package may not be installed, or the command may not be in the current PATH. Install the distribution package that supplies net-tools if required, or use the modern command:

ip addr show

eth0 does not exist

The system may use a predictable name such as enp0s3, ens33, or eno1. It is also possible that an adapter is absent, disabled, or undetected. List detected interfaces with:

ifconfig -a
ip link show

Use the detected name in later commands.

An interface is missing from ordinary output

It may be down or inactive. Run ifconfig -a to include inactive interfaces. If appropriate, enable it with elevated privileges.

An address was assigned but other networks are unreachable

Check the address and netmask, then inspect routes with modern routing tools. A default gateway may be missing, or the address and mask may not match the connected network. Also check the cable or Wi-Fi association, VLAN settings, upstream network, and firewall.

IP connectivity works but hostnames do not resolve

DNS servers may be missing or misconfigured. ifconfig does not manage DNS. Check the active resolver configuration and the settings managed by NetworkManager, systemd-networkd, netplan, or the applicable system tool.

The change disappears after reboot or reconnecting

ifconfig made a runtime-only change, or a DHCP client or network-management service replaced it. Configure the address through the distribution's supported persistent network configuration mechanism.

An SSH session disconnects after a change

The edited interface probably carried the SSH connection, or the new address changed the return path. Use console access for changes to a remote machine when possible, and verify the management interface before applying modifications.

Practical Inspection Workflow

  1. List every detected interface with ifconfig -a.
  2. Identify the real interface name; do not assume it is eth0.
  3. Inspect that interface with ifconfig <interface>.
  4. Record its current address, netmask, flags, MAC address, and link-related counters.
  5. For a temporary test, apply an appropriate non-conflicting address with sudo ifconfig.
  6. Verify the result and separately check routes, gateway reachability, DNS, and firewall behavior.
  7. Restore the previous settings or create persistent configuration through the supported network-management system.

Exam-Relevant Notes

  • ifconfig displays and changes network-interface settings; it is not a complete network-configuration system.
  • ifconfig -a includes inactive interfaces, while plain ifconfig may not.
  • 255.255.255.0 is equivalent to the CIDR prefix /24.
  • lo is the loopback interface used for local host-to-self communication.
  • Interface names vary; eth0 is a traditional example, not a universal name.
  • ifconfig does not configure DNS, automatically add all required routes, or make settings persistent.
  • iproute2's ip command is the modern Linux replacement for most ifconfig tasks.

For current administration practice, learn both the legacy ifconfig syntax and the modern ip tools, while remembering that distribution network managers are responsible for persistent configuration.

Related learning: Linux tutorials and Bourne Again Shell (Bash).