net.rst 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. .. _pcsys_005fnetwork:
  2. Network emulation
  3. -----------------
  4. QEMU can simulate several network cards (e.g. PCI or ISA cards on the PC
  5. target) and can connect them to a network backend on the host or an
  6. emulated hub. The various host network backends can either be used to
  7. connect the NIC of the guest to a real network (e.g. by using a TAP
  8. devices or the non-privileged user mode network stack), or to other
  9. guest instances running in another QEMU process (e.g. by using the
  10. socket host network backend).
  11. Using TAP network interfaces
  12. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  13. This is the standard way to connect QEMU to a real network. QEMU adds a
  14. virtual network device on your host (called ``tapN``), and you can then
  15. configure it as if it was a real ethernet card.
  16. Linux host
  17. ^^^^^^^^^^
  18. As an example, you can download the ``linux-test-xxx.tar.gz`` archive
  19. and copy the script ``qemu-ifup`` in ``/etc`` and configure properly
  20. ``sudo`` so that the command ``ifconfig`` contained in ``qemu-ifup`` can
  21. be executed as root. You must verify that your host kernel supports the
  22. TAP network interfaces: the device ``/dev/net/tun`` must be present.
  23. See :ref:`sec_005finvocation` to have examples of command
  24. lines using the TAP network interfaces.
  25. Windows host
  26. ^^^^^^^^^^^^
  27. There is a virtual ethernet driver for Windows 2000/XP systems, called
  28. TAP-Win32. But it is not included in standard QEMU for Windows, so you
  29. will need to get it separately. It is part of OpenVPN package, so
  30. download OpenVPN from : https://openvpn.net/.
  31. Using the user mode network stack
  32. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. By using the option ``-net user`` (default configuration if no ``-net``
  34. option is specified), QEMU uses a completely user mode network stack
  35. (you don't need root privilege to use the virtual network). The virtual
  36. network configuration is the following::
  37. guest (10.0.2.15) <------> Firewall/DHCP server <-----> Internet
  38. | (10.0.2.2)
  39. |
  40. ----> DNS server (10.0.2.3)
  41. |
  42. ----> SMB server (10.0.2.4)
  43. The QEMU VM behaves as if it was behind a firewall which blocks all
  44. incoming connections. You can use a DHCP client to automatically
  45. configure the network in the QEMU VM. The DHCP server assign addresses
  46. to the hosts starting from 10.0.2.15.
  47. In order to check that the user mode network is working, you can ping
  48. the address 10.0.2.2 and verify that you got an address in the range
  49. 10.0.2.x from the QEMU virtual DHCP server.
  50. Note that ICMP traffic in general does not work with user mode
  51. networking. ``ping``, aka. ICMP echo, to the local router (10.0.2.2)
  52. shall work, however. If you're using QEMU on Linux >= 3.0, it can use
  53. unprivileged ICMP ping sockets to allow ``ping`` to the Internet. The
  54. host admin has to set the ping_group_range in order to grant access to
  55. those sockets. To allow ping for GID 100 (usually users group)::
  56. echo 100 100 > /proc/sys/net/ipv4/ping_group_range
  57. When using the built-in TFTP server, the router is also the TFTP server.
  58. When using the ``'-netdev user,hostfwd=...'`` option, TCP or UDP
  59. connections can be redirected from the host to the guest. It allows for
  60. example to redirect X11, telnet or SSH connections.
  61. Hubs
  62. ~~~~
  63. QEMU can simulate several hubs. A hub can be thought of as a virtual
  64. connection between several network devices. These devices can be for
  65. example QEMU virtual ethernet cards or virtual Host ethernet devices
  66. (TAP devices). You can connect guest NICs or host network backends to
  67. such a hub using the ``-netdev
  68. hubport`` or ``-nic hubport`` options. The legacy ``-net`` option also
  69. connects the given device to the emulated hub with ID 0 (i.e. the
  70. default hub) unless you specify a netdev with ``-net nic,netdev=xxx``
  71. here.
  72. Connecting emulated networks between QEMU instances
  73. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  74. Using the ``-netdev socket`` (or ``-nic socket`` or ``-net socket``)
  75. option, it is possible to create emulated networks that span several
  76. QEMU instances. See the description of the ``-netdev socket`` option in
  77. :ref:`sec_005finvocation` to have a basic
  78. example.