Networking in QEMU

Networking in QEMU



Checking the networking interface

QEMU emulates a small sub-network (or LAN if you will) containing a DHCP server, a gateway, and a DNS server; everything you need to access the internet.
There are also some optional components that can be added to this emulated network. The DNS and gateway backs onto your host machine's internet connection.
This means the QEMU VM session has internet access.

Boot QEMU and log in to the system. Use the ifconfig utility to check out the networking setup. This will be similar to below:

root@amd-edf:~# ifconfig eth0 Link encap:Ethernet HWaddr 00:0A:35:00:22:01 inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::20a:35ff:fe00:2201/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2 errors:0 dropped:0 overruns:0 frame:0 TX packets:25 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1152 (1.1 KiB) TX bytes:4732 (4.6 KiB) Interrupt:30 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

eth0, in this case, is the Cadence GEM. Some network traffic is already accumulated, RX and TX bytes. This is probably for the DHCP acquisition that happened during boot. 

Testing the Network

We can use this network connection normally, almost as if it were attached to the host machines network. For example, you can download a file from AMD Github repository. In the booted Linux on QEMU, enter the command:

root@amd-edf:~# wget https://github.com/Xilinx/qemu-devicetrees/archive/master.zip

The output should be something like:

Connecting to codeload.github.com (192.30.255.120:443) master.zip 100% |**********************************************************| 133k 0:00:00 ETA

This is a source code tarball for the DTS project retrieved from AMD public Github repository.

unzip the downloaded zip file to see if our download worked:

root@amd-edf:~# unzip master.zip

Output:

Archive: master.zip creating: qemu-devicetrees-master/ inflating: qemu-devicetrees-master/.gitignore inflating: qemu-devicetrees-master/Makefile inflating: qemu-devicetrees-master/README inflating: qemu-devicetrees-master/board-versal-pmc-ddrmc-virt.dts inflating: qemu-devicetrees-master/board-versal-pmc-vc-p-a2197-00.dts inflating: qemu-devicetrees-master/board-versal-pmc-vc-pa2197-00.dts inflating: qemu-devicetrees-master/board-versal-pmc-virt.dts inflating: qemu-devicetrees-master/board-versal-ps-cosim-vc-p-a2197-00.dts inflating: qemu-devicetrees-master/board-versal-ps-cosim-virt.dts inflating: qemu-devicetrees-master/board-versal-ps-vc-p-a2197-00.dts .....

File Transfer with TFTP

QEMU has built-in TFTP capability to allow for easy file transfer to/from the guest machine to the host. Exit QEMU if it is running from before, and on the terminal for the host machine, make a new directory with a file it:

mkdir -p /home/${USER}/qemu-training-tftp echo "hello QEMU world" >> /home/${USER}/qemu-training-tftp/file.txt

file.txt in this new directory will contain our "hello QEMU world" line of text.

QEMU needs an additional argument to have TFTP access do that directory:

-tftp /home/${USER}/qemu-training-tftp

If using PetaLinux, restart QEMU with the following modified command:

petalinux-boot --qemu --prebuilt 3 --qemu-args "-tftp /home/${USER}/qemu-training-tftp"

This will override the default TFTP directory setting to our new directory. Any TFTP request we initiate from the guest will point at this directory we just created.
The built-in TFTP server IP is 10.0.2.2. Log in to the Zynq UltraScale+ MPSoC VM and download the file from the TFTP server:

root@amd-edf:~# tftp -g -r file.txt 10.0.2.2

  cat the file to see if the contents are correct:

root@amd-edf:~# cat file.txt

File Transfer with SSH

Files can be transferred between the host and guest machines via SSH by using the scp command.

scp syntax is:

scp <source-path> <dest-path>

And the remote path has the syntax of:

user@host:/path/to/file

For example, if copying a file from the host machine to the guest machine, the command might look something like:

root@amd-edf:~# scp <your host machine username>@<your host machine IP>:/scratch/doc-example/myapp.elf . Host '<host IP>' is not in the trusted hosts file. (ecdsa-sha2-nistp256 fingerprint sha1!! 18:7e:92:d0:33:ed:97:e7:cb:b2:f7:b1:5d:52:5f:a6:34:9a:97:f9) Do you want to continue connecting? (y/n) y komlodi@<host IP>'s password: myapp.elf 100% 18KB 17.7KB/s 00:00 root@amd-edf:~#

SSH into QEMU

To SSH into QEMU, some additional arguments need to be passed into QEMU.

For example, if using PetaLinux in a Zynq UltraScale+ MPSoC project, add the following arguments with the petalinux-boot command:

petalinux-boot --qemu --prebuilt 3 --qemu-args "-net nic -net nic -net nic -net nic,netdev=eth0 -netdev user,id=eth0,hostfwd=tcp::1114-:22"

Or if using PetaLinux on a Versal adaptive SoCs project:

petalinux-boot --qemu --prebuilt 3 --qemu-args "-net nic,netdev=eth0 -netdev user,id=eth0,hostfwd=tcp::1114-:22 -net nic"

Log in to the QEMU machine. From host machine terminal, run the command shown below to access QEMU via SSH:

ssh -p 1114 root@localhost

If you terminate QEMU and re-run it. Depending on your host machine SSH configuration, you might see the following error when trying to SSH to QEMU:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that a host key has just been changed. .... .... RSA host key for [localhost]:1115 has changed and you have requested strict checking. Host key verification failed.

This happened due to remote host id changes as shown in the above error message. One way to avoid this is to supply a different port (instead of 1114) each time you boot QEMU.

To completely avoid this, you can skip the host key checking by sending the key to a null known_hosts file. As shown below:

ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" root@localhost -p 1114

Connecting to the VM

In the above examples, we did inbound connections to the VM. We will now create another inbound connection, where the VM itself acts as a server. This will be a telnet connection.
Boot QEMU Linux with the following extra port redirection argument:

petalinux-boot --qemu --prebuilt 3 --qemu-args "-redir tcp:<port>:10.0.2.15:23" # Chose your favorite number between 2000 and 10000 for <port>. # Make sure port number is something unique to avoid port collision with other users of the same server machine.

Log in as normal. There are not many differences to observe in the boot sequence with this change.

The construction of this redirection argument is:

© 2025 Advanced Micro Devices, Inc. Privacy Policy