>_cmd.script

ifconfig

Display and configure network interfaces

Networking

By CMD Script Team · 4 min read · Last updated

SYNTAX
ifconfig [INTERFACE] [OPTIONS | ADDRESS]

Options

Command options and flags
FlagDescription
-aShow all interfaces, including those that are currently down
upActivate the specified interface, e.g. ifconfig eth0 up
downDeactivate the specified interface, e.g. ifconfig eth0 down
netmaskSet the subnet mask when assigning an address, e.g. netmask 255.255.255.0
mtuSet the interface's Maximum Transmission Unit in bytes, e.g. mtu 1400
hw etherSet the interface's MAC (hardware) address, e.g. hw ether 00:11:22:33:44:55

Distribution compatibility

  • Ubuntu
  • Debian
  • Fedora
  • Arch
  • macOS

What it does

ifconfig displays and configures network interfaces: viewing IP addresses, netmasks, MAC addresses, and interface statistics (packets sent/received, errors), or changing them — assigning an address, bringing an interface up or down, adjusting the MTU. It's part of the older net-tools suite, and while still present and functional on many systems, it has been formally deprecated on Linux in favor of the ip command from iproute2. Knowing ifconfig is still valuable because it appears constantly in older scripts, documentation, and exam material.

Beginner examples

  • ifconfig — show all currently active (up) interfaces
  • ifconfig -a — show every interface, including ones that are down
  • ifconfig eth0 — show details for a single named interface
  • sudo ifconfig eth0 up / sudo ifconfig eth0 down — activate or deactivate an interface
ifconfig -a

Advanced examples

  • Assign a static IP and netmask directly on the command line (non-persistent, resets on reboot): sudo ifconfig eth0 192.168.1.50 netmask 255.255.255.0
  • Set a custom MTU to troubleshoot fragmentation issues over a VPN or tunnel interface: sudo ifconfig tun0 mtu 1400
  • Spoof or set a specific MAC address for testing: sudo ifconfig eth0 hw ether 00:11:22:33:44:55
  • Check interface error/drop counters when diagnosing packet loss: ifconfig eth0 | grep -E "RX packets|TX packets|errors"
sudo ifconfig eth0 down && sudo ifconfig eth0 up

Common mistakes

  • Assuming changes made with ifconfig persist across reboots — they don't; you need distro-specific network configuration files (netplan, NetworkManager, systemd-networkd) for persistent settings.
  • Running ifconfig on a fresh minimal install and getting "command not found" because net-tools isn't installed by default anymore — install it, or switch to ip addr.
  • Forgetting sudo when trying to change interface state or address, since these operations require root privileges.
  • Confusing ifconfig's "RUNNING" flag (link is actually up) with the interface being administratively "UP" — an interface can be up but not running if there's no carrier (e.g., unplugged cable).

Tips

  • Use ifconfig -a when troubleshooting to make sure you're not missing an interface that exists but is currently down.
  • Pipe ifconfig output through grep to extract just what you need, e.g. ifconfig eth0 | grep "inet " for the IPv4 address.
  • If ifconfig isn't installed, ip addr and ip link cover the same ground and are worth learning alongside it, since they're the actively maintained tool going forward.

Best practices

  • For any configuration meant to survive a reboot, use your distro's proper network configuration mechanism (netplan/NetworkManager/systemd-networkd) rather than hand-running ifconfig commands.
  • Prefer ip for new scripts and automation — it has a more consistent, scriptable output format (and ip -j gives JSON), whereas ifconfig's text output varies across implementations and is harder to parse reliably.
  • When documenting runbooks, mention both the ifconfig and ip equivalent commands, since operators may be working on systems where only one is installed.

Try it yourself

A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.

Real-world use cases

  • Quickly checking an interface's IP address and traffic counters on a legacy server during troubleshooting.
  • Bringing a flaky network interface down and back up as a first troubleshooting step after a driver hiccup.
  • Setting a temporary IP address on a lab or test VM without touching persistent network configuration files.

Common interview questions

  • Why is ifconfig considered deprecated on Linux? It's part of the unmaintained net-tools package, replaced by iproute2's ip command, which supports newer networking features (namespaces, more interface types) and has a more consistent interface.
  • What's the ip command equivalent of ifconfig eth0 up? ip link set eth0 up.
  • How would you assign a static IP temporarily (non-persistently) to an interface? sudo ifconfig eth0 192.168.1.50 netmask 255.255.255.0, understanding it won't survive a reboot without additional persistent configuration.

Frequently Asked Questions

Is ifconfig deprecated?

Yes, on modern Linux distributions. It comes from the old net-tools package, which has been officially replaced by iproute2's `ip` command (`ip addr`, `ip link`) for years. Many rolling-release distros like Arch don't install net-tools by default anymore, and even Debian/Ubuntu/Fedora treat it as optional. macOS still ships ifconfig as a first-class, actively used tool (it's BSD-derived), so it remains fully current there.

What's the ip equivalent of ifconfig -a?

`ip addr show` (or `ip a` for short) lists all interfaces and their addresses, including ones that are down — it's the modern replacement.

How do I bring an interface up or down with ifconfig?

`sudo ifconfig eth0 up` activates it; `sudo ifconfig eth0 down` deactivates it. Both require root privileges.

Why doesn't ifconfig show my new virtual/container interface?

ifconfig may simply not be installed, or on some systems it doesn't automatically enumerate interfaces created after boot without `-a`. If the interface truly doesn't appear with `-a` either, check `ip link show` instead, since `ip` is more consistently maintained for newer interface types (veth, bridges, etc.).

Cheat sheet

Download a quick-reference cheat sheet for ifconfig.