ifdown 和“ip link set .. .down”有什么区别?

ifdown 和“ip link set .. .down”有什么区别?

我在下面做了一些测试。看来ifdown ens32接口并没有关闭。并且ip link仍然显示UP。只会ip link set ens32 down导致接口关闭。那么这里有什么问题呢?为什么ifdown无法关闭接口?

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:[~]# 

答案1

事实并非如此。

ifupifdown读取/etc/network/interfaces,除了打开和关闭接口之外,它们还在 中执行大量脚本/etc/network,这为各种事物(例如 DHCP)提供了钩子。

另一方面,ip link ...(新变体)和ifconfig ... up/down(旧变体)直接设置接口的状态,而不执行接口启动和关闭时可能需要的任何附加操作。

因此,如果ifdown不起作用,您的系统可能未配置为使用经典/etc/network/interfaces系统(例如,因为它使用systemd,它的所有操作都不同),或者首先执行的某些脚本中存在错误,或者可能是其他原因。

答案2

新命令(做事的新方式)和旧命令之间没有区别ip- 曾经有ipconfignetstat和。请参阅此处进行比较:arproute

https://p5r.uk/blog/2010/ifconfig-ip-comparison.html

https://www.howtoing.com/ifconfig-vs-ip-command-comparing-network-configuration/

但是,ifupifdown是网络脚本的一部分,其执行的功能不仅仅是上面列出的每个命令。也许您的网络是由邪恶的或不同的网络管理员管理的。尝试

rpm -qf `/sbin/ifdown`

查看是否可能ifdown是某些网络管理包的一部分 - 这在不同的发行版中有所不同。

因此,也许您需要更改网络配置工具管理网络的方式。

相关内容