I have been trying to get interconnection between host and guest for a while [ubuntu18.04 - kvm qemu] because I am preconfiguring a webserver and I want to use the guest as a test bed. Overall, I can't go much further because the guest does have access to the host but not the other way around.
Searching I have read that I must create a bridge, and to do so modify /etc/networ/interfaces as follows (This is how I left it):
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
#a partir de aqui esta lo nuevo
auto br0
iface br0 inet static
address 192.168.1.37
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1
bridge_ports enp4s0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
of course in all the tutorials they mention eth0, however in ubuntu it does not exist and instead it is enp4s0.
Interestingly, after restarting the network service
/etc/init.d/network-manager restart
when checking the changes with ifconfig -a... no change appears and it looks like this.
enp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.37 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::dd0b:4362:2668:e119 prefixlen 64 scopeid 0x20<link>
ether da:01:3a:03:c0:67 txqueuelen 1000 (Ethernet)
RX packets 365643 bytes 484283142 (484.2 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 177556 bytes 16509811 (16.5 MB)
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 (Bucle local)
RX packets 2566 bytes 247445 (247.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2566 bytes 247445 (247.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:7f:cc:c1 txqueuelen 1000 (Ethernet)
RX packets 83 bytes 5750 (5.7 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 57 bytes 5832 (5.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0-nic: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:7f:cc:c1 txqueuelen 1000 (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
enp4s0 was supposed to lose its IP and br0 shows up with my host's IP, but br0 doesn't show up. If I open virt-manager, in the network section of each machine it recognizes a new br0 bridge mode over enp4s0, however when the machine starts it tells me that the br0 device does not exist.
It's been a week and I'm getting too frustrated, I can't find any tutorial on the subject (mentioning ubuntu 18.04) even if I know that eth0 doesn't exist in ubuntu. And the few who perhaps mention it, following in its footsteps, doesn't matter, because br0 never gets created. I will be very grateful if you can tell me where I am missing.
PS: I have the bridge-utils package installed and updated
Well I finally found a clue and thanks to it I solved the problem.
It turns out that ubuntu 18.04 (I think in fact that a couple of versions later too) manages networks with netplan, so the typical devices named as eth0, etc. are renamed in another way and it is in charge of writing about the files of setting. That's why no tutorial ended up working and ended up having conflicts. I'm not an expert on the matter (if I were I wouldn't have had this problem) but that's what I've come to understand.
to the mess:
you have to work with a yaml file, netplan checks the syntax and it takes care of making the changes in the network configuration. The steps would be this simple:
Important to check which are our devices. With the ifconfig command, for example, we can see what the equivalent of eth0 would be, in my case it is enp4s0.
We proceed to modify the /etc/netplan/01-network-manager-all.yaml file with an editor such as nano or vim. it is possible that the final file is called something else on your system.
something like this will appear:
We will only have to add a "few" lines that will define the bridge and the connection. It should be as follows:
(note that in my case I have decided to use static address, but you can save a couple of lines by using dhcp mode)
Finally we have 3 commands to know: sudo netplan try sudo netplan generate sudo netplan apply
With the first one we have plenty, because first it does a syntax check and then tests the connection, giving you room to test it and save the changes.
and... the end (hallelujah)