ifdown Command in Linux

November 20, 2023

Introduction

Linux ifdown command is a basic Linux command used to deactivate a network interface. It's often grouped with ifup and ifquery due to the similarities.

The following text elaborates on Linux ifdown command.

ifdown Command in Linux

Prerequisites

  • Linux system (this tutorial uses Ubuntu 22.04).
  • Access to the terminal.
  • ifdown command installed.
  • sudo permissions.

Note: For the proper ifdown functioning, the file /run/network/ifstate must be writable. If it's not, the solution is using sudo or root privileges or --force.
Another option is to make /run/network/ifstate a symbolic link to a writable location.

ifdown Command Syntax

The ifdown command syntax is:

ifdown [options] [interface]

Running ifdown without any options or interface doesn't produce output. The [interface] components are mandatory. However, options serve to customize the command but are not necessary.

Note: If the ifdown command is not available on the system, run sudo apt install ifupdown.

ifdown Command Options

The ifdown command has several arguments which change its output. The following table lists ifdown options:

OptionDescription
-a, --allDeactivates all interfaces.
--allow CLASSIgnores non-"allow-CLASS" interfaces in /etc/network/interfaces.
-i, --interfaces FILEUses FILE for interface definitions instead of /etc/network/interfaces.
--state-dir DIRUses DIR to store state information.
-X, --exclude PATTERNExcludes interfaces from the list of interfaces to operate on by the PATTERN.
-n, --no-actSimulates the command without actually executing it.
-v, --verboseShows what would happen before executing.
-o OPTION=VALUE
 
Sets OPTION to VALUE as though it were in /etc/network/interfaces.
--no-mappingsDoesn't run any mappings.
--no-scriptsDoesn't run hook scripts.
-nvPrints non-verbose output.
--no-loopbackPrompts the command not to perform any deactivation on the loopback device.
--forceForces the command to run even if the interface is not configured.
--ignore-errorsSignals the command to ignore errors.
-h, --helpPrints the help message.
-V, --version Prints copyright and version information.

Note: The --force option addresses a common issue with ifdown. Network interface records sometimes become inconsistent with the actual states of the interfaces. In such cases, --force enables ifdown to execute deconfiguration commands, irrespective of its perception of the interface's current state.

ifdown Command Examples

Due to the variety of arguments, ifdown has multiple practical examples. However, before running ifdown, a user must know the interface names. Use the ip or deprecated ifconfig command to check interface names.

For instance, to verify the interface names with ip, run:

ip link show
ip link show terminal output

On the other hand, use the following command to accomplish the same:

ifconfig -a

ifcconfig -a terminal oitput

Both commands show currently active network interfaces.

Note: The ifconfig command is deprecated and not always installed in modern Linux systems. To install it, run sudo apt install net-tools.

The following sections present some ifdown use cases.

Bring Down Active Interfaces

Do deactivate all interfaces, run:

sudo ifdown -a

The command has no output.

Print Verbose Output

To display additional info in the command output, run the command with -v:

sudo ifdown -av
sudo ifdown -av

To verify all interfaces are down, use the ping command. For instance, ping Google with:

ping google.com
Ping Google terminal output

The command prints no output.

Disable a Specific Interface

To bring down a specific interface, use the syntax:

sudo ifdown -v [interface][configuration]

This command provides a verbose output. For instance, turn off the specific configuration of the interface lo with:

sudo ifdown -v lo=lo
sudo ifdown lo=lo -v terminal output

Use ifconfig or ip link show to confirm the interface is not listed.

Note: In some cases, bringing up the interface without the configuration is enough. For instance, sudo ifdown -v lo executes without errors. However, this is not always sufficient.

Simulate Interface Deactivation

Simulating network interface deactivation without altering system configurations is beneficial for testing and development. The procedure allows users to test the deactivation impact before implementing changes to the network, ensuring a controlled and predictable environment. This is especially useful when scripting or automating network interface management processes.

To simulate the command without executing it, run:

ifdown --no-act [configuration][interface]

For instance, to simulate ifdown on the lo interface without executing the command, run:

ifdown --no-act lo=lo
sudo ifdown --noact lo=lo terminal oitput

Note: Automating network configuration for hardware changes may need extra packages (e.g., udev, ifplugd), but many Linux distributions include basic networking by default. Check system documentation or the package manager to see if these extras are installed and necessary for your needs.

Conclusion

After reading this article, you know everything about the Linux ifdown command. Additionally, the guide provided the most common use cases.

To learn about other Linux commands, refer to our Linux commands cheat sheet.

Was this article helpful?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
Best Tools to Monitor Network Bandwidth on a Linux Server
May 4, 2019

There are many different tools for monitoring network traffic...
Read more
Linux Network Commands Cheat Sheet
September 13, 2023

Master Linux networking commands! This article provides an overview of 20...
Read more
How to Find or Check Your IP Address in Linux
November 17, 2023

An IP address is a code assigned to a computer on a network. It works as a postal...
Read more
What is SNMP (Simple Network Management Protocol)?
October 20, 2022

This article explains what SNMP is, its basic components, and how it woks. See which network...
Read more