天天看點

libvirt網絡分析之---為什麼修改網絡後虛拟機會斷網

在libvirt官方wiki有這麼一段關于網絡的介紹:

Applying modifications to the network

Sometimes, one needs to edit the network definition and apply the changes on the fly. The most common scenario for this is adding new static MAC+IP mappings. Very unfortunately, destroying and re-defining the network causes the guests to lose network connectivity with the host until their network interfaces are re-attached.

In order to solve this problem, one possible approach would be to use a script to re-attach all interfaces on all machines after the network has been re-defined

接着昨天的,

上面這段話大概說的是,當我們需要實時修改network的配置并使之生效的時候,就得重新啟動此network,也就是需要net-destroy再net-start一下,我們的配置才能生效,但是随之而來的問題是,當network被重新啟動之後,虛拟機便無法通路網絡了,除非把虛拟機的network interface重新attach一下,或者等到虛拟機重新啟動,那麼為什麼會出現這樣的問題呢?我們先從它的表象開始分析,至于是否要追究到源碼裡面就取決于同學們自己了,反正我暫時沒那功夫。這裡僅僅是抛出來了一塊磚。

當一個network啟動之後,會自動生成一個虛拟網卡接口如virbr1,也會生成其他一些需要的東西,而重新啟動了libvirt的network之後這個接口也會被重新開機,是以就導緻了中途有一個中斷的過程,

那事情就比較清晰了,如果你将libvirt啟動網絡的所有過程拆分開來一個一個的手動生成,需要修改某一部配置設定置的時候實際上你隻需要修改對應的配置檔案而不需要重新啟動這個virbr1接口,比如上面提到的mac+ip的綁定,如果把dnsmasq獨立出來,不讓libvirt接管,那麼增加了mac+ip綁定之後,僅僅需要重新開機dnsmasq這個服務。

當然具體裡面所涉及到的細節還需要慢慢研究,這裡就先到這