![如何重新啟動網路介面?](https://rvso.com/image/23943/%E5%A6%82%E4%BD%95%E9%87%8D%E6%96%B0%E5%95%9F%E5%8B%95%E7%B6%B2%E8%B7%AF%E4%BB%8B%E9%9D%A2%EF%BC%9F.png)
如何重新啟動網路介面?我的虛擬機器在家庭和工作之間切換時無法正確更新其 IP 位址。虛擬機器運行 Ubuntu 伺服器並使用橋接網路適配器。
答案1
答案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
)。