如何重新啟動網路介面?

如何重新啟動網路介面?

如何重新啟動網路介面?我的虛擬機器在家庭和工作之間切換時無法正確更新其 IP 位址。虛擬機器運行 Ubuntu 伺服器並使用橋接網路適配器。

答案1

用於ifdown將其關閉並ifup重新開啟。重啟eth0

> ifdown eth0
> ifup eth0

您將需要 root 權限。

更多細節關於ifupifdown.

答案2

聽起來您已經使用 DHCP 設定了該介面。如果是這樣,您需要終止現有的 DHCP 用戶端,然後重新啟動它。對於許多發行版,您可以這樣做:

dhcpcd -k eth0
dhcpcd -d eth0

但並非每個發行版都使用dhcpcd.我知道一些用途dhclient,Debian 不使用嗎pump

此外,「eth0」可能不構成正確的介面名稱:請執行此操作ifconfig -a以查看該虛擬機器具有什麼。

答案3

在 Debian 下,您可以告訴介面取得另一個 DHCP 租約

dhclient -v {interface_name}

-v意味著“詳細”,並將向您展示正在執行的過程。

如果介面配置為從 DHCP 取得位址,@JustinY 的答案將會起作用(ifup和指令)。ifdown如果它們配置為靜態,它們將恢復為靜態 IP。 dhclient無論如何都會嘗試聯繫 DHCP 伺服器。

答案4

其他答案看起來不錯。只是想從頁面添加man

   -a, --all
          If  given  to  ifup,  affect  all  interfaces  marked auto.  Interfaces are
          brought up in the order in which they are  defined  in  /etc/network/inter‐
          faces.   Combined with --allow, acts on all interfaces of a specified class
          instead.  If given to ifdown, affect all  defined  interfaces.   Interfaces
          are  brought  down  in  the order in which they are currently listed in the
          state file. Only interfaces  defined  in  /etc/network/interfaces  will  be
          brought down.

一般來說,--all了解該標誌可能非常有幫助,因為它會將網路作為一個整體來顯示(前提是介面被標記為auto)。

相關內容