Linux
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:[~]#
沒有區別是不正確的。
ifup
和ifdown
read/etc/network/interfaces
,除了啟動和關閉介面之外,它們還在 中執行許多腳本/etc/network
,這些腳本為各種事物(如 DHCP)提供了鉤子。另一方面,
ip link ...
(新變體)和ifconfig ... up/down
(舊變體)直接設置介面的狀態,不執行任何在介面上升和下降時可能需要的額外操作。因此,如果
ifdown
不起作用,則您的系統可能未配置為使用經典/etc/network/interfaces
系統(例如,因為它使用systemd
,它的所有操作都不同),或者某些首先執行的腳本中的某處出現錯誤,或者可能是其他一些原因。