配置网络以允许 QEMU 访问互联网

配置网络以允许 QEMU 访问互联网

我有以下标准配置:

  • 连接到互联网的远程服务器,我只能使用 SSH 进行控制
  • 在此服务器上,有一个 QEMU 实例

我正在尝试找到正确的配置,以便 QEMU 实例可以访问互联网(这样我就可以从 QEMU 下载文件)。

根据我所读到的内容,我必须使用 TAP 网络,但我不完全确定它是什么。

按照教程,我成功创建了一个“tap0”界面。另外,根据我一直关注的文档 [1],我必须设置一个“桥”。然后我将接口“tap0”添加到网桥,并且我还应该添加物理接口“eth0”。不幸的是,一旦我将物理接口添加到网桥,我就会失去与服务器的 SSH 连接(我确实需要避免这种情况)。

有没有一种方法可以进行配置:

  • 允许 QEMU 实例访问互联网
  • 保持对服务器的 SSH 访问
  • 最终将一些特定端口从主机转发到QEMU实例

编辑:我当前的/etc/network/interfaces:

auto tap0
iface tap0 inet static
        pre-up tunctl -t tap0
        address 192.168.101.1
        netmask 255.255.255.0

auto br0
iface br0 inet static
        address 192.168.1.10
        network 192.168.1.1
        netmask 255.255.255.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
        bridge_ports enp1s0 tap0
        up brctl stp br0 on

ifconfig 的输出:

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 186.165.216.145  netmask 255.255.255.0  broadcast 188.165.215.255
        inet6 2001:41d0:2:a28c::  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::225:90ff:fe7b:a1a0  prefixlen 64  scopeid 0x20<link>
        ether 00:25:90:7b:a1:a0  txqueuelen 1000  (Ethernet)
        RX packets 7463  bytes 785704 (767.2 KiB)
        RX errors 0  dropped 3  overruns 0  frame 0
        TX packets 471  bytes 48743 (47.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:58:62:89:a3  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 186.165.216.145  netmask 255.255.255.0  broadcast 188.165.215.255
        ether 00:25:90:7b:a1:a0  txqueuelen 1000  (Ethernet)
        RX packets 43202  bytes 6202060 (5.9 MiB)
        RX errors 0  dropped 7  overruns 0  frame 0
        TX packets 41815  bytes 13945866 (13.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xfbce0000-fbd00000

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Boucle locale)
        RX packets 10792  bytes 11008366 (10.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10792  bytes 11008366 (10.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tap0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.101.1  netmask 255.255.255.0  broadcast 192.168.101.255
        ether b2:ab:00:ed:63:bb  txqueuelen 1000  (Ethernet)
        RX packets 10  bytes 882 (882.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 801  bytes 50917 (49.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[1]http://www.shakthimaan.com/installs/debian-tun-tap-setup.html

相关内容