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.
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:
Option | Description |
---|---|
-a , --all |
Deactivates all interfaces. |
--allow CLASS |
Ignores non-“allow-CLASS” interfaces in /etc/network/interfaces. |
-i , --interfaces FILE |
Uses FILE for interface definitions instead of /etc/network/interfaces. |
--state-dir DIR |
Uses DIR to store state information. |
-X , --exclude PATTERN |
Excludes interfaces from the list of interfaces to operate on by the PATTERN . |
-n , --no-act |
Simulates the command without actually executing it. |
-v , --verbose |
Shows what would happen before executing. |
-o OPTION=VALUE |
Sets OPTION to VALUE as though it were in /etc/network/interfaces. |
--no-mappings |
Doesn’t run any mappings. |
--no-scripts |
Doesn’t run hook scripts. |
-nv |
Prints non-verbose output. |
--no-loopback |
Prompts the command not to perform any deactivation on the loopback device. |
--force |
Forces the command to run even if the interface is not configured. |
--ignore-errors |
Signals the command to ignore errors. |
-h , --help |
Prints 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
On the other hand, use the following command to accomplish the same:
ifconfig -a
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
To verify all interfaces are down, use the ping command. For instance, ping Google with:
ping google.com
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
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
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.
Đăng ký liền tay Nhận Ngay Bài Mới
Subscribe ngay
Cám ơn bạn đã đăng ký !
Lỗi đăng ký !
Add Comment