QEMU 的来宾操作系统中的网络如何工作?
我在理解客户操作系统(Ubuntu)中的 Qemu 和网络如何工作方面遇到了问题。我已阅读本手册和其他内容。如果我理解的话,如果你想在客户操作系统中连接互联网,你需要在主机操作系统中创建点击界面。然后链接 eth0 和 tap0 接口:
- 通过使用 NAT 路由
- 通过使用网桥(链接 tap0 和 eth0-host
中有这些接口(ppp0 - 3G-调制解调器 - 互联网,lo):
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.245.146.78 P-t-P:10.64.64.64 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:49635 errors:0 dropped:0 overruns:0 frame:0
TX packets:42745 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:52405401 (52.4 MB) TX bytes:5988643 (5.9 MB)
在 gust 操作系统(eth0,lo)中:
eth0 Link encap:Ethernet HWaddr:52:54:00:12:34:56
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
...
互联网在 gust 操作系统中工作!如果我在真实 ppp0 和来宾接口之间没有链接,那么来宾操作系统中的网络如何以及为何工作?我什至没有任何人在主机中为来宾操作系统提供接口。
如果我理解这是因为来宾通过默认主机接口转发数据。但为什么?
Qemu 选项:
qemu -hda ~/virt.disk -cdrom /dev/cdrom -boot once=dc -m 1024M -usb -smp 2 -enable-kvm
主机路由表:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.64.64.64 * 255.255.255.255 UH 0 0 0 ppp0
default 10.64.64.64 0.0.0.0 UG 0 0 0 ppp0
访客路由表:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.2.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
default 10.0.2.2 0.0.0.0 UG 0 0 0 eth0
I've got a problem about understanding how Qemu and network in guest OS (Ubuntu) work. I've read this manual and others. And if I understand, if you want to pick up Internet in guest OS you need to make tap interface in host OS. After then to link eth0 and tap0 interfaces:
- By using NAT-routing
- By using bridge ( link tap0 and eth0-host)
Now I have these interfaces in host (ppp0 - 3G-modem - Internet, lo):
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.245.146.78 P-t-P:10.64.64.64 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:49635 errors:0 dropped:0 overruns:0 frame:0
TX packets:42745 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:52405401 (52.4 MB) TX bytes:5988643 (5.9 MB)
In gust OS (eth0, lo):
eth0 Link encap:Ethernet HWaddr:52:54:00:12:34:56
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
...
Internet in gust OS work! How and why is working network in guest OS if I don't have link between real ppp0 and guest interface? I haven't even anyone interface in host for guest OS.
If I understand that's because guest forward data through default host interface. But why?
Qemu options:
qemu -hda ~/virt.disk -cdrom /dev/cdrom -boot once=dc -m 1024M -usb -smp 2 -enable-kvm
Host routing table:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.64.64.64 * 255.255.255.255 UH 0 0 0 ppp0
default 10.64.64.64 0.0.0.0 UG 0 0 0 ppp0
Guest routing table:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.2.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
default 10.0.2.2 0.0.0.0 UG 0 0 0 eth0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎想要使用 TAP 设备,但遇到问题。
要使用 TAP,您的 qemu 命令行中应该有类似这样的内容:
在这些参数中,将 rtl8139 替换为计算机上任何可用的 nic 设备。如果您不知道可用的 nic 设备,请使用以下命令列出它们:
您还必须确保已创建 TAP 设备。以下脚本创建必要的网桥和端口:
运行此脚本后,使用 -net tap 参数启动的虚拟机应已做好网络准备并使用 TAP。
It looks like you want to use the TAP device but having problems with it.
To use TAP you should have something like this to your qemu command line:
In those arguments, replace rtl8139 with any available nic device on your machine. If you don’t know the available nic devices use the following command to list them:
You also must insure that the TAP device is created. The following script create the necessary bridge and ports:
After running this script, VMs started with the -net tap arguments should be network ready and using TAP.