QEMU network configuration in QNX(русская версия)QEMU hardware emulator provides broad range of networking capabilities. Large set of emulated network controllers makes it possible (NE2000, Intel 82551, Intel 82557B, Intel 82559ER, Realtek RTL8139, Intel E1000 etc.), and allows networking in majority of guest systems. It hard to find advanced OS, which doesn't support NE2000 or RTL8139. Flexible network configurations and interactions between guest and host systems also play big role. In this article we will discuss various network configurations for QEMU in QNX host. Additional information you can also find in the Internet, and keep in mind that QNX6 networking subsystem is very similar to NetBSD.
Note 1. In all examples Archlinux installation CD (archlinux-2009.08-netinstall-i686.iso) is used as a guest system. But you can configure network the same way in other guest OS, for example Windows, QNX 4.25 or NetBSD, considering its specifics. QNX Neutrino 6.4.1 is used as a host system, but you can use QNX 6.4.0 or QNX 6.5.0.Note 2. Following notation conventions are used in examples:
- [QNX] -- command is executed on the QNX host system;
- [ARCH] -- command is executed on the guest system, in our case Archlinux.Network user modeThe easiest way to connect to host system is the user mode. In this mode QEMU provides:
- virtual network (10.0.2.0)
- firewall which doesn't allow any external connections
- DHCP server (10.0.2.2)
- gateway (10.0.2.2)
DHCP server automatically assigns 10.0.2.15 to your interface when a DHCP request is received from guest system. When the host system (QNX) is connected to the Internet, the guest will be automatically be able to access the Internet too. No additional steps are required.
1.
[QNX] Start virtual machine:
# qemu -net user -net nic -cdrom /home/qemu/img/archlinux-2009.08-netinstall-i686.iso
2.
[ARCH] Configure network interface:
In different operating systems network interface configuration using DHCP may differ. For example, in QNX you should execute following: 3.
[ARCH] Test network:
# ping -c2 10.0.2.2
# telnet 10.0.2.2
Connecting virtual networksYou need to execute first QEMU process, which would wait for incoming connections on a specific port. Second QEMU process would connect to that port. Each time new packet appears in first QEMU virtual network, it is transfered into second network and vice versa.
Realize following configuration:
-
Guest system 1 waits for incoming connection on
8010 port;
-
Guest system 2 connects to
guest system 1 through
localhost:8010.
1.
[QNX] Start
guest system 1:
# qemu -net nic,macaddr=52:54:00:12:34:57 -net socket,listen=:8010 -cdrom /home/qemu/img/archlinux-2009.08-netinstall-i686.iso
2.
[QNX] Start
guest system 2:
# qemu -net nic,vlan=2,macaddr=52:54:00:12:34:56 -net socket,vlan=2,connect=127.0.0.1:8010 -cdrom /home/qemu/img/archlinux-2009.08-netinstall-i686.iso
3.
[ARCH1] Configure network on the
guest system 1:
# ifconfig eth0 10.0.2.101 netmask 255.255.255.0 up
4.
[ARCH2] Configure network on the
guest system 2:
# ifconfig eth0 10.0.2.102 netmask 255.255.255.0 up
5.
[ARCH] Test network on both guest systems:
Connecting virtual network to TAP deviceThere is another way to create virtual network: using a virtual Ethernet device --
TAP driver. Ethernet frames received by such device will be also sent to the guest system's virtual network. Of course, Ethernet frames sent by guest system's virtual network will be also received by TAP device.
Using
devnp-qtap.so driver for QNX6, applications are allowed to interact with a network device using a simple file descriptor. Any data sent over the file descriptor will be received on both sides. This means that applications running on the guest system will be able to access and connect to applications running on the host system. If port forwarding is allowed, guest applications can also access the Internet.
With the
-net tap option QEMU will try to execute
/etc/qemu-ifup script to configure TAP device and
/etc/qemu-ifdown script after closing the device. If
/etc/qemu-ifup is not found, program will be terminated. You can change default script names, or specify not to run them. For example:
# qemu -net tap,script=no,downscript=no <...>
To avoid specifying these options every time, you can create empty
/etc/qemu-ifup script. Do not forget to set executable flag for file.
1.
[QNX] Create and configure TAP device:
# mount -T io-pkt /lib/dll/devnp-qtap.so
# ifconfig tap0 10.0.0.1 netmask 255.255.255.0 up
2.
[QNX] Start virtual machine:
# qemu -net nic -net tap,ifname=/dev/tap0 -cdrom /home/qemu/img/archlinux-2009.08-netinstall-i686.iso
3.
[ARCH] Configure network interface:
# ifconfig eth0 10.0.0.2 netmask 255.255.255.0 up
# ifconfig
4.
[ARCH] Test network:
# ping -c 2 10.0.0.1
# telnet 10.0.0.1
5.
[QNX] Test network:
Connecting virtual networks to TAP devices (two guest systems)In this example we'll have 2 guest systems (two TAP devices). Each guest system is connected to host system using TAP device. In order to allow connections between guest systems you have to setup bridge between both TAP devices. Bridge will be central network node between host and both network systems.
1.
[QNX] Create and configure TAP devices:
# mount -T io-pkt /lib/dll/devnp-qtap.so
# ifconfig tap0 10.0.0.1 netmask 255.255.255.0 up
# mount -T io-pkt /lib/dll/devnp-qtap.so
# ifconfig tap1 10.0.1.1 netmask 255.255.255.0 up
2.
[QNX] Start
guest system 1:
# qemu -net tap,ifname=/dev/tap0 -net nic,macaddr=80:00:00:12:34:57 -cdrom /home/qemu/img/archlinux-2009.08-netinstall-i686.iso
3.
[QNX] Start
guest system 2:
# qemu -net tap,ifname=/dev/tap1 -net nic,macaddr=80:00:00:12:34:56 -cdrom /home/qemu/img/archlinux-2009.08-netinstall-i686.iso
4.
[QNX] Create and configure bridge interface:
# ifconfig bridge0 create
# brconfig bridge0 add tap0 add tap1 up
5.
[ARCH1] Configure network in
guest system 1:
# ifconfig eth0 10.0.0.2 netmask 255.255.0.0 up
6.
[ARCH2] Configuring network in
guest system 2:
# ifconfig eth0 10.0.1.2 netmask 255.255.0.0 up
7. Test network using ping. In all cases you should be able to ping/access any system no matter what system you operate on.