特別答覆:
You can create a new interface in the networking panel, based on an existing interface, but it will not act as a real fully functional interface (if the original interface is inactive, then the derived one is also inactive).
這可以使用TUN/TAP設備通過psv141所建議,並操縱/Library/Preferences/SystemConfiguration/preferences.plist
文件添加基於任一個桶或抽頭接口一個網絡服務來實現。 Mac OS X將不允許基於虛擬網絡接口創建NetworkService,但可以直接操作preferences.plist
文件以手動添加NetworkService。基本上你會打開Xcode中的preferences.plist
文件(或直接編輯XML,但Xcode可能更加傻瓜式),並從現有的以太網接口複製配置。創建新NetworkService的地方位於「NetworkServices」下,如果您的Mac具有以太網設備,則NetworkService配置文件也將位於此屬性條目下。以太網進入可複製幾乎一字不差,你實際上可以改變的唯一領域是:
- UUID
- UserDefinedName
- IPv4配置和接口設置爲您屯或自來水設備(即TUN0或tap0中)。
- DNS服務器,如果需要。
然後你也可以操縱你想要的這個NetworkService的特定位置(記住Mac OS X可以配置所有依賴於你的「位置」的網絡接口)。默認位置UUID可以在PropertyList的根目錄中作爲關鍵字「CurrentSet」獲取。在確定了所需的位置(或集合)後,展開Set屬性,然後在Global/IPv4/ServiceOrder下添加新NetworkService的UUID條目。同樣在Set屬性下,您需要展開Service屬性,並將UUID作爲字典添加到字典中,其中一個字符串條目使用鍵__LINK__,值爲UUID(使用其他接口作爲示例)。
修改preferences.plist
文件後,只需重新啓動,NetworkService將在SystemPreferences-> Network下可用。請注意,我們模擬了以太網設備,因此Mac OS X網絡層將會注意到「電纜被拔出」,並且不會讓您通過GUI激活接口。但是,由於底層設備是tun/tap設備並且具有IP地址,因此該接口將變爲活動狀態,並且將在BSD級別添加正確的路由。
作爲參考,這是用來做特殊的路由魔術。
如果你有這麼多並且遇到麻煩,你必須通過打開/ dev /下的其中一個設備來創建tun/tap設備。您可以使用任何程序來做到這一點,但我的好老式下的風扇自己:
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
int main()
{
int fd = open("/dev/tun0", O_RDONLY);
if (fd < 0)
{
printf("Failed to open tun/tap device. Are you root? Are the drivers installed?\n");
return -1;
}
while (1)
{
sleep(100000);
}
return 0;
}
您的同一主題,或多或少http://compileyouidontevenknowyou.blogspot.com/2009/03/virtual-networking-with-virtualbox-on.html – 2009-03-27 01:56:22
「我知道,你可以做一個Windows中的虛擬網絡接口(請參見此處),而在Linux中,使用ip-aliases也很容易「 - WUT?使用ip-aliases創建接口?事實上,你不知道這件事。 – poige 2016-10-20 14:52:11