QEMU 的来宾操作系统中的网络如何工作?

发布于 2024-10-07 15:00:23 字数 2037 浏览 4 评论 0原文

我在理解客户操作系统(Ubuntu)中的 Qemu 和网络如何工作方面遇到了问题。我已阅读本手册和其他内容。如果我理解的话,如果你想在客户操作系统中连接互联网,你需要在主机操作系统中创建点击界面。然后链接 eth0tap0 接口:

  1. 通过使用 NAT 路由
  2. 通过使用网桥(链接 tap0eth0-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:

  1. By using NAT-routing
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声静候 2024-10-14 15:00:23

您似乎想要使用 TAP 设备,但遇到问题。
要使用 TAP,您的 qemu 命令行中应该有类似这样的内容:

-net nic,model=rtl8139 -net tap

在这些参数中,将 rtl8139 替换为计算机上任何可用的 nic 设备。如果您不知道可用的 nic 设备,请使用以下命令列出它们:

qemu -net nic,model=?

您还必须确保已创建 TAP 设备。以下脚本创建必要的网桥和端口:

# For Network Bridging/TAP
# Set permissions of tun device
chown root.users /dev/net/tun 
chmod g+rw /dev/net/tun

#Add a bridge, add eth0
brctl addbr br0
ifconfig eth0 0.0.0.0 promisc
brctl addif br0 eth0
dhclient br0

# Create tap0
tunctl -t tap0 -u username #replace username by your username

# Enable tap0
brctl addif br0 tap0
ifconfig tap0 up

运行此脚本后,使用 -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:

-net nic,model=rtl8139 -net tap

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:

qemu -net nic,model=?

You also must insure that the TAP device is created. The following script create the necessary bridge and ports:

# For Network Bridging/TAP
# Set permissions of tun device
chown root.users /dev/net/tun 
chmod g+rw /dev/net/tun

#Add a bridge, add eth0
brctl addbr br0
ifconfig eth0 0.0.0.0 promisc
brctl addif br0 eth0
dhclient br0

# Create tap0
tunctl -t tap0 -u username #replace username by your username

# Enable tap0
brctl addif br0 tap0
ifconfig tap0 up

After running this script, VMs started with the -net tap arguments should be network ready and using TAP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文