在 RHEL7 中永久停用 NIC 接口

在 RHEL7 中永久停用 NIC 接口

如何在RHEL7中永久停用NIC介面?禁用後“ifconfig -a”不應顯示介面?

有什麼想法嗎?

答案1

這可以透過簡單地缺少配置來實現。如何實現這一點取決於您使用 NetworkManager 還是傳統的 ifupdown。您所希望的只是相關 NIC 上沒有 IP 位址,您可以透過不為其提供 IP 位址來實現此目的。我將給出傳統網路的解決方案,因為我對 NetworkManager 有意見。

每個 NIC 的配置儲存在/etc/sysconfig/network-scripts/名為ifcfg-eth0.這些是您將在其中放置逐行配置選項的檔案。下面是一個 NIC 的範例,它不會嘗試透過 DHCP 取得 IP,也不會透過「address=」欄位靜態為其指派 IP(未列出,因為我們沒有為其提供位址)

在進行這些修改之前,您需要使用現有設定來關閉 NIC。這可以透過 來完成ifdown eth0。我假設您想要的 NIC 是 eth0,但您尚未指定要停用哪一個。名稱可以有多種形式,因此請根據口味進行調整。

DEVICE="eth0"
BOOTPROTO=none # note here that "none" will disable DHCP
NM_CONTROLLED="no" #This prevents NetworkManager from controlling this interface, honoring only the config elements in this file
PERSISTENT_DHCLIENT=1 #Irrelevant in the absence of DHCP
ONBOOT="yes" # You could change this to "no" to prevent the interface from coming up even at layer 2
TYPE=Ethernet
DEFROUTE=yes #Irrelevant in the absence of DHCP
PEERDNS=yes #Irrelevant in the absence of DHCP
PEERROUTES=yes #Irrelevant in the absence of DHCP
IPV4_FAILURE_FATAL=yes #Irrelevant if you're not even giving it an IPv4 address
IPV6INIT=no # Change this to "no" to prevent from getting an IPv6 address
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME="eth0"

完成該配置後,您可以發出命令ifup eth0以查看您的配置是否符合您的要求。

相關內容