Ubuntu ifconfig Command: View/Configure Network Interfaces

In Ubuntu systems, network configuration is fundamental for daily operations and troubleshooting. The ifconfig command (Interface Configuration) is a classic tool for viewing and configuring network interfaces. For beginners, mastering its basic usage can quickly resolve most network-related issues.

I. What is a Network Interface?

In computer networking, a network interface is the “channel” through which the system communicates with external networks. Examples include wired network cards (typically named eth0, ens33, etc.), wireless network cards (e.g., wlan0), and the local loopback interface lo (used for internal system communication). Each interface has a unique MAC address (physical address) and an IP address (logical address).

II. How to View Network Interface Information?

The most common use of ifconfig is to display the status and parameters of network interfaces.

1. Basic Usage (No Parameters)

Execute ifconfig without any arguments to show information about all enabled network interfaces on the system:

ifconfig

2. Output Interpretation (Example Scenario)

  • eth0/ens33 (Wired Interface):
  • inet 192.168.1.100: Interface IP address (e.g., 127.0.0.1 indicates the loopback interface).
  • netmask 255.255.255.0: Subnet mask (divides IP into network and host portions).
  • ether 00:11:22:33:44:55: MAC address (unique hardware identifier).
  • RX packets/TX packets: Number of received/transmitted packets (useful for traffic analysis).
  • UP: Interface is enabled; DOWN indicates it is disabled.

  • lo (Loopback Interface):
    This interface is used for internal system communication. Its IP is fixed at 127.0.0.1 (IPv4) or ::1 (IPv6). It only supports local program-to-program communication and cannot provide external services.

3. Extended Parameters

  • View All Interfaces (Including Disabled Ones):
  ifconfig -a

Even if an interface is unplugged or disabled, -a will display its name and status.

  • View Brief Information (Quick Troubleshooting):
  ifconfig -s

Output is concise, showing key metrics like interface name, MTU (Maximum Transmission Unit), and RX/TX rates.

III. How to Temporarily Configure Network Interfaces?

ifconfig can also temporarily modify interface parameters (resets after reboot, suitable for quick testing).

1. Set IP Address and Subnet Mask Temporarily

Syntax: ifconfig <interface> <IP address> netmask <subnet mask>
Example: Set ens33 (wired interface) to 192.168.1.200 with subnet mask 255.255.255.0:

sudo ifconfig ens33 192.168.1.200 netmask 255.255.255.0
  • sudo: Required for administrative privileges to modify system settings.
  • To set a default gateway, use the route command (e.g., route add default gw 192.168.1.1).

2. Enable/Disable Interfaces

  • Enable Interface: If DOWN, execute:
  sudo ifconfig ens33 up
  • Disable Interface: To disconnect temporarily:
  sudo ifconfig ens33 down

IV. Notes and Common Issues

  1. Permission Issues:
    Modifications require sudo. Without it, you’ll get “permission denied”:
   # Incorrect (no sudo):
   ifconfig ens33 up
   # Correct (with sudo):
   sudo ifconfig ens33 up
  1. Temporary vs. Permanent Configuration:
    - ifconfig changes only apply to the current session. For permanent IP configuration, use:

    • Ubuntu 18.04+: netplan (YAML configuration files) or
    • Older systems: Modify /etc/network/interfaces.
  2. Missing ifconfig?
    Ubuntu 20.04+ may exclude net-tools (where ifconfig resides) by default. Install it first:

   sudo apt update && sudo apt install net-tools

V. Summary

ifconfig is a powerful tool for quick network troubleshooting, with core functions:
- View interface status (focus on UP status and IP address).
- Use ifconfig -a to check all interfaces (including disabled ones).
- Temporarily configure IP with ifconfig <interface> <IP> netmask <subnet> and enable/disable with up/down.

While Ubuntu recommends netplan for long-term configuration, ifconfig remains invaluable for rapid local network diagnostics. For persistent setup, learn netplan or modify /etc/netplan/*.yaml instead of relying on ifconfig for temporary changes.

Tip: For long-term network stability, prioritize netplan or system configuration files over ifconfig for temporary adjustments.

Xiaoye