Linux Commands GuideLinux Tutorials

15 Useful ifconfig Commands to Configure Network Interface in Linux

Introduction

This guide shows 15 useful ifconfig commands to configure network interfaces in Linux. You'll learn how to view interfaces, assign IPs, set netmasks and broadcast addresses, adjust MTU, create aliases, change MACs, and enable promiscuous mode. The examples target beginners and intermediate users who need reliable, repeatable steps to configure a network interface. If you prefer modern tooling, note that the **ip** command from **iproute2** is the recommended replacement for many tasks, but ifconfig remains widely used and useful for quick troubleshooting.

Prerequisites

Before you begin, ensure you have:

  • Local shell access to the Linux system (SSH or direct console).
  • An account with privileges to change network settings. Many commands require elevated rights—we use
    sudo

    where needed. sudo temporarily runs a command as the superuser (root) and is required to change network device state or install packages.

  • The net-tools package installed to provide ifconfig on modern distributions.

Installation

Install net-tools if ifconfig is not available.

Debian / Ubuntu

sudo apt update
sudo apt install -y net-tools

Explanation:

sudo apt update

refreshes package lists.

sudo apt install -y net-tools

installs the package that supplies ifconfig. The

-y

flag auto-confirms the installation.

RHEL / CentOS / Fedora

sudo yum install -y net-tools       # RHEL/CentOS 7
sudo dnf install -y net-tools       # Fedora, RHEL/CentOS 8+

Explanation:

sudo yum install

or

sudo dnf install

installs the package; package manager depends on your distribution.

Setup: 15 Practical ifconfig Commands

Below are 15 common ifconfig commands with brief explanations of what each does and why you might use it. Replace the example device eth0 and IP addresses with your system's interface name and addressing.

1. View active network interfaces

ifconfig

Explanation: Shows all active interfaces and their addresses, RX/TX packets, and errors. No

sudo

needed to view; useful for a quick status check.

2. Display all interfaces (active and inactive)

ifconfig -a

Explanation: The

-a

flag lists every interface, including those that are down. Use this to discover inactive devices or aliases that don't appear with plain

ifconfig

.

3. View a specific interface

ifconfig eth0

Explanation: Limits output to eth0. Use the actual interface name on your system (example: enp0s3 on some systems).

4. Enable (bring up) an interface

sudo ifconfig eth0 up

Explanation: Brings the interface online so it can send/receive traffic. Use

sudo

because changing interface state requires elevated privileges. Alternative:

sudo ifup eth0

on systems that support ifup/ifdown scripts.

5. Disable (bring down) an interface

sudo ifconfig eth0 down

Explanation: Takes the interface offline. Useful when changing MAC addresses, MTU, or testing network state. If your distribution uses network service scripts,

sudo ifdown eth0

is also common.

6. Assign an IP address

sudo ifconfig eth0 172.16.25.125

Explanation: Assigns IP 172.16.25.125 to eth0. This sets the IPv4 address but not the netmask or broadcast unless specified. Use

sudo

because IP assignment modifies kernel networking state.

7. Set a netmask

sudo ifconfig eth0 netmask 255.255.255.224

Explanation: Configures the interface netmask. Netmask defines the network portion of the IP; combine with IP assignment when needed.

8. Set a broadcast address

sudo ifconfig eth0 broadcast 172.16.25.63

Explanation: Explicitly sets the broadcast address for the interface. Rarely required if IP + netmask imply the correct broadcast, but necessary in some network setups.

9. Assign IP, netmask and broadcast together

sudo ifconfig eth0 172.16.25.125 netmask 255.255.255.224 broadcast 172.16.25.63

Explanation: Single command to set IP, netmask, and broadcast atomically. Useful for deterministic configuration and scripts.

10. Change MTU (Maximum Transmission Unit)

sudo ifconfig eth0 mtu 1000

Explanation: Sets the MTU to 1000 bytes. MTU limits the size of packets; lowering MTU can help avoid fragmentation over some links, while increasing may improve throughput on stable links. Not all NICs support arbitrary MTU values.

11. Enable promiscuous mode

sudo ifconfig eth0 promisc

Explanation: Puts the interface into promiscuous mode so it accepts all frames seen on the wire, not just those addressed to it. Required for packet capture tools like tcpdump or wireshark on that interface.

12. Disable promiscuous mode

sudo ifconfig eth0 -promisc

Explanation: Removes the interface from promiscuous mode and restores normal filtering. Use this to reduce noise or security exposure after packet capture.

13. Add an alias interface

sudo ifconfig eth0:0 172.16.25.127 netmask 255.255.255.224

Explanation: Creates an alias interface (eth0:0) with its own IP in the same subnet. Useful to host multiple IPs on one physical interface for virtual hosting or service separation.

14. Remove an alias

sudo ifconfig eth0:0 down

Explanation: Shuts down and removes the alias eth0:0. Aliases are logical and will not persist across reboots unless added to network config files.

15. Change (spoof) the MAC address

sudo ifconfig eth0 down
sudo ifconfig eth0 hw ether 00:11:22:33:44:55
sudo ifconfig eth0 up

Explanation: Best practice is to bring the interface down, set the MAC with

hw ether

, and then bring it back up. Use a valid unicast MAC format. Changing MAC can help with privacy, testing, or bypassing MAC-based filters—but ensure compliance with your network policy.

Verification

After making changes, verify the new state:

ifconfig eth0

Explanation: This shows the current settings for eth0. Check the IP, netmask, broadcast, MTU, and flags (e.g., UP, BROADCAST, RUNNING, PROMISC).

To verify routing and connectivity:

ip route show
ping -c 3 8.8.8.8

Explanation:

ip route show

lists routing table entries (modern alternative to route).

ping

tests basic IP connectivity. Both are safe verification steps;

sudo

is not required for ping or read-only route queries.

Persistence across reboots

Changes with ifconfig are ephemeral by default. To make settings persistent, add them to your distribution's network configuration files or use NetworkManager:

  • Debian/Ubuntu (ifupdown): edit **/etc/network/interfaces** or create an interface stanza.
  • RHEL/CentOS: use **/etc/sysconfig/network-scripts/ifcfg-eth0** and appropriate variables.
  • NetworkManager: use nmcli or the GUI to persist settings.

Explanation: Editing these files ensures the network is configured automatically at boot. Use proper syntax for your distro; incorrect changes can prevent network service startup.

Troubleshooting

Common issues and fixes

  • No ifconfig command: install net-tools (see Installation).
  • Interface does not come up: check
    dmesg | tail -n 50

    for driver errors and verify physical link/cable.

  • Wrong IP or route conflicts: inspect
    ifconfig -a

    and

    ip route show

    , and remove conflicting aliases with

    ifconfig eth0:0 down

    .

  • Changes lost after reboot: add configuration to appropriate persistent network files or configure via NetworkManager.
  • Permissions denied: prefix commands with
    sudo

    or become root with

    sudo -i

    . Explanation: elevated privileges are required to change kernel networking state.

When to use ip instead of ifconfig

The ifconfig tool is part of the legacy net-tools suite. For many tasks, the modern ip command from the iproute2 package is preferred. Examples:

ip addr show         # view addresses (replacement for ifconfig)
sudo ip addr add 172.16.25.125/27 dev eth0    # set IP and netmask

Explanation:

ip

gives more consistent, extensible controls over IP addresses, routes, and links and is the recommended tool for scripting and newer distributions.

Conclusion

These 15 ifconfig commands cover the most common tasks to configure network interfaces in Linux: view interfaces, assign IPs/netmasks/broadcasts, toggle interfaces, set MTU, manage promiscuous mode, create aliases, and change MAC addresses. Use ifconfig commands for quick checks and legacy systems, but consider adopting modern Linux network commands like ip for production automation. Always use

sudo

when making changes, verify with

ifconfig -a

or

ip addr show

, and persist settings via your distro's network configuration files such as **/etc/network/interfaces** or the NetworkManager tools.

Komentariši

Vaša email adresa neće biti objavljivana. Neophodna polja su označena sa *