Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux ifdown Command

Linux ifdown Command in Detail

Linux Command Reference Linux Command Reference


What is the ifdown command

ifdown is a command-line tool in Linux used to deactivate (disable) network interfaces. It is ifupdown part of the software package, and is usually paired with the ifup command.

Basic Functionality


Command syntax



ifdown [选项] <接口名称>

Parameter Description

Common options

Option Description
-a Deactivate /etc/network/interfaces all entries marked as in auto interfaces
--force Force deactivation of an interface even if it already appears to be down
--verbose Display detailed execution output
-i FILE Use the specified configuration file instead of the default one /etc/network/interfaces
-X Do not run the scripts specified in the configuration file

Usage examples

Example 1: Deactivate a single network interface

Example

sudo

ifdown

eth0

Result of execution:

Example 2: Deactivate all automatically configured interfaces

Example

sudo

ifdown

-a

Notes:

Example 3: Deactivate an interface in verbose mode

Example

sudo

ifdown

--verbose

wlan0

Output example:

Configuring interface wlan0=wlan0 (inet)

run-parts --verbose /etc/network/if-down.d

Executing /etc/network/if-down.d/wpasupplicant

wlan0     Link encap:Ethernet  HWaddr 00:1a:2b:3c:4d:5e  

          inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0

          ...


Configuration file details

ifdown The behavior of the command is mainly controlled by the /etc/network/interfaces file. A typical configuration is as follows:

Example

Ethernet interface

auto eth0

iface eth0 inet dhcp

Wireless interface

auto wlan0

iface wlan0 inet static

    address 192.168.1.100

    netmask 255.255.255.0

    gateway 192.168.1.1

    wpa-ssid MyWiFi

    wpa-psk mypassword

Configuration parameter description

Parameters Description
auto Specify the interfaces that should be brought up automatically at system startup
iface Define an interface configuration
inet Specify IPv4 configuration
dhcp Use DHCP to obtain an IP address automatically
static Use a static IP configuration

Common Problem Solutions

Problem 1: Interface cannot be deactivated

Error message:

ifdown: interface eth0 not configured

Solution:

  1. Verify that the interface name is correct:ip link show
  2. Check whether the interface is defined in the configuration file
  3. Try forcing deactivation:sudo ifdown --force eth0

Problem 2: Insufficient permissions

Error message:

ifdown: insufficient privileges for operation

Solution:

Problem 3: Configuration file error

Error message:

ifdown: /etc/network/interfaces: line 5: syntax error

Solution:

  1. Check the configuration file syntax:sudo nano /etc/network/interfaces
  2. Ensure each line of the configuration is correctly formatted
  3. Comment out suspicious lines for testing

Best Practices

  1. Check before operating: Before executing ifdown first use ip a to confirm the interface status
  2. Use the full path: It is recommended to use /sbin/ifdown rather than directly using ifdown
  3. Record changes: Back up files before modifying network configuration:sudo cp /etc/network/interfaces /etc/network/interfaces.bak
  4. Test environment first: Verify important changes in a test environment first
  5. Alternatives: Consider using ip command (modern alternative):sudo ip link set eth0 down

Comparison with related commands

Command Function Tool package it belongs to Recommendation
ifdown Deactivate an interface ifupdown ★★★☆☆
ip link set down Deactivate an interface iproute2 ★★★★★
nmcli connection down Deactivate a connection NetworkManager ★★★★☆

Modern recommendation: On newer systems, prefer using the ip command rather than ifdown, because ifupdown tool package is being gradually phased out.


Summary

ifdown command is one of the fundamental tools for Linux network management. Although it is gradually being replaced by more modern tools on newer systems, it remains useful on many older systems and in specific scenarios. Understanding how it works and how it is configured helps you better manage system network connections.

Key points review:

  1. ifdown Needs to be used together with /etc/network/interfaces Using Configuration Files
  2. Usually requires root privileges to run
  3. Modern systems recommend using ip command as an alternative
  4. Operating on network interfaces may affect system connectivity; proceed with caution

Linux Command Reference Linux Command Reference