[SOLVED] Host to guest connection over network (tap?)

Hi guys, I’m trying to test a server I’m writing and I’ve been wondering if I can simulate a LAN with Gnome Boxes. I need to be able to send requests to the server in the Guest OS from the Host and receive the replies.

From what I could find online, I would need to setup a tap device to do this. However it seems like I already have one:

▶ ifconfig
enp5s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.10  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::28b1:c96:58c8:b461  prefixlen 64  scopeid 0x20<link>
        ether 08:60:6e:7b:cf:e8  txqueuelen 1000  (Ethernet)
        RX packets 5914311  bytes 8383048729 (7.8 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3336213  bytes 253513648 (241.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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 1000  (Local Loopback)
        RX packets 2450  bytes 1076315 (1.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2450  bytes 1076315 (1.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tap0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fc05:50ff:fe2a:88a3  prefixlen 64  scopeid 0x20<link>
        ether fe:05:50:2a:88:a3  txqueuelen 1000  (Ethernet)
        RX packets 39  bytes 4704 (4.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 51  bytes 4974 (4.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:52:0b:c0  txqueuelen 1000  (Ethernet)
        RX packets 39  bytes 4158 (4.0 KiB)
        RX errors 0  dropped 5  overruns 0  frame 0
        TX packets 6  bytes 492 (492.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

However pinging and trying to ping/connect to tap0 doesn’t work. I always get an Invalid Argument Error.

My host is Fedora 31 (kernel 5.5) and my guest is Ubuntu 19.10 (kernel 5.3).

Do I need some to setup something else, or get into qemu’s configuration?

For qemu, I needed to do

nmcli connection add type tun
connection.interface-name tap0
tun.mode tap tun.owner $(id -u)
ipv4.method shared
ipv4.addresses 172.28.112.1/24

(copied from
https://guix.gnu.org/manual/en/html_node/Networking-Services.html#Networking-Services),
tested on multiple OS but not Fedora nor Ubuntu.

I then needed to add

-nic tap,ifname=tap0,script=no,downscript=no

to QEMU launch options. Though if you want to use gnome-boxes, I
suppose you need some libvirt stuff instead of these launch options.

Regards,
Florian

@pelzflorian thanks for helping! I didn’t use your commands in the end but you gave me a good hint.
You can use virt-manager to manage boxes’ images, as I found out via this tutorial.

Turns out this was automatically setup (maybe by boxes). If you open the virtual machine in virt-manager and go to the details page you can see the network settings, and most importantly the IP address.

I was able to confirm it’s working by running a test http server in the guest:

$ python3 -m http.server

And then calling it from the host:

$ curl 192.168.10.169:8000

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso8859-1">
<title>Directory listing for /</title>
</head>
<body>

(etc etc)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.