What's the differences between ifdown and "ip link set .. .down"?

5,741

It's not true that there's no difference.

ifup and ifdown read /etc/network/interfaces, and on top of bringing the interfaces up and down, they execute lots of scripts also in /etc/network, which provides hooks for various things (like DHCP).

On the other hand, ip link ... (new variant) and ifconfig ... up/down (old variant) set the state of the interface directly, not doing any of the additional actions that may be necessary if an interface goes up and down.

So if ifdown doesn't work, your system is probably not configured to use the classic /etc/network/interfaces system (for example, because it uses systemd, which does everything differently), or there's an error somewhere in some script that's excute first, or possibly some other reason.

Share:
5,741
yagmurdursun
Author by

yagmurdursun

Updated on September 18, 2022

Comments

  • yagmurdursun
    yagmurdursun over 1 year

    I did some testing below. It seems ifdown ens32 didn't bring the interface down. And ip link still show UP. Only ip link set ens32 down brings the interface down. So what's the problem here? Why ifdown can't bring down the interface?

    root:[~]# cat /etc/*release*
    Oracle Linux Server release 7.6
    NAME="Oracle Linux Server"
    VERSION="7.6"
    ID="ol"
    VARIANT="Server"
    VARIANT_ID="server"
    VERSION_ID="7.6"
    PRETTY_NAME="Oracle Linux Server 7.6"
    ANSI_COLOR="0;31"
    CPE_NAME="cpe:/o:oracle:linux:7:6:server"
    HOME_URL="https://linux.oracle.com/"
    BUG_REPORT_URL="https://bugzilla.oracle.com/"
    
    ORACLE_BUGZILLA_PRODUCT="Oracle Linux 7"
    ORACLE_BUGZILLA_PRODUCT_VERSION=7.6
    ORACLE_SUPPORT_PRODUCT="Oracle Linux"
    ORACLE_SUPPORT_PRODUCT_VERSION=7.6
    Red Hat Enterprise Linux Server release 7.6 (Maipo)
    Oracle Linux Server release 7.6
    cpe:/o:oracle:linux:7:6:server
    root:[~]# 
    root:[~]# ip link
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
        link/ether 00:50:56:31:a8:12 brd ff:ff:ff:ff:ff:ff
    3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
        link/ether 52:54:00:33:cf:a3 brd ff:ff:ff:ff:ff:ff
    4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN mode DEFAULT group default qlen 1000
        link/ether 52:54:00:33:cf:a3 brd ff:ff:ff:ff:ff:ff
    root:[~]# ifdown ens32
    Device 'ens32' successfully disconnected.
    root:[~]# ip link
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
        link/ether 00:50:56:31:a8:12 brd ff:ff:ff:ff:ff:ff
    3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
        link/ether 52:54:00:33:cf:a3 brd ff:ff:ff:ff:ff:ff
    4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN mode DEFAULT group default qlen 1000
        link/ether 52:54:00:33:cf:a3 brd ff:ff:ff:ff:ff:ff
    root:[~]# ip link set ens32 down
    root:[~]# ip link
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    2: ens32: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
        link/ether 00:50:56:31:a8:12 brd ff:ff:ff:ff:ff:ff
    3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
        link/ether 52:54:00:33:cf:a3 brd ff:ff:ff:ff:ff:ff
    4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN mode DEFAULT group default qlen 1000
        link/ether 52:54:00:33:cf:a3 brd ff:ff:ff:ff:ff:ff
    root:[~]# 
    
  • 炸鱼薯条德里克
    炸鱼薯条德里克 over 4 years
    Does iprouter2 include netstat functionality
  • Ned64
    Ned64 over 4 years
    @炸鱼薯条德里克 The replacement for netstat in the new ip System is called ss.
  • dirkt
    dirkt over 4 years
    Note that this is true for ifconfig vs. ip, but not for ifup and ifdown.
  • Ned64
    Ned64 over 4 years
    @dirkt Thanks, I corrected by mistake!