Solved How to duplicate the tap0 interface in a new tap1 network interface that it is not used

At the end I've been able to get the result I wanted even without having fixed the main problem. I'm partially satisfied. But it works,so,its ok for now. The main problem that it seems affects only my FreeBSD installation is still there (any bhyve vm [based on linux and on windows] is not able to connect to internet because there is some misconfiguration on my FreeBSD host [not documented or badly documented on the various web sites that I've reached,including the official FreeBSD manual : it means that if I follow the instructions shown there,it will not work],BUT I've been able to get working the audio and the networking of a Linux Ubuntu VM using vm-bhyve,simply using this config file :

Code:
loader="uefi"
cpu=8
memory=8GB
network0_type="virtio-net"
network0_switch="public"
disk0_type="virtio-blk"
disk0_name="ubuntu-budgie-gpu.img"
uuid="ca6be87e-eed2-11eb-abbb-e0d55ee21f22"
network0_mac="58:9c:fc:0a:b1:92"
graphics="yes"
graphics_res="1440x900"
xhci_mouse="yes"
bhyve_options="-s 20,hda,play=/dev/dsp8,rec=/dev/dsp8"

it didn't work from the beginning because I used an occupied slot. Problem is that if I use an occupied slot,vm-bhyve doesn't give any error,so a newbie don't know that the VM does not boot because it is using an occupied slot (-s) OR 'cause 1000 other reasons. I think that's not good to don't show specific error messages,because they are useful to help the user to understand whats wrong and they help to fix problems. Anyway thanks to everyone that helped me with their experience,patience and generosity.
 
Last edited:
BTW, I never use Network Manager in linux, always had trouble with it -- ALWAYS. But since you ARE using it... can you check what's in /etc/resolv.conf?
Another thing you can do to test network is, rather then ping $hostname , you ping $some_local_address. You'll see at least if networking is working at all. Because Network Manager is such a bad thing... it will
I know, you said it worked for you with vm-bhyve, but still...
Also, I remember setting up tap bridge for my VM at work... There were some funny things about it. I wasn't able to set it up just following those posts -- it worked one way, but not the other. But it's working now and I'll post once I get to work on Monday.
EDIT: haha, I'm a bit late... Still , the point about network testing is good for the future.
 
I don't want to give up. Usually the unfixed problems still remains inside my head and in the future they will come back again and again until I find the solution. I'm not expert,but I'm tenacious. At the moment I'm collecting new informations for fixing the bhyve networking problem. Someone suggested to do a "tcpdump" ; I tried it and this is what happened : https://ibb.co/Y2fHYrC ; can someone tell me if the result that I got is great or not ? Someone says : "Having em0 getting back an IP address suggests that a DHCP client is still running on the wrong interface" ; so,the solution is close.

/etc/resolv.conf (on freebsd)

Code:
search homenet.telecomitalia.it
nameserver 127.0.0.1
options edns0

/etc/resolv.conf (on ubuntu)

Code:
nameserver 127.0.0.53
options edns0 trust-ad
search homenet.telecomitalia.it
 
I promised to post my tap bridge config.
Here it is, it starts from /etc/rc.conf:
Code:
.......................
##bridge-related part##
cloned_interfaces="bridge0 tap0"
ifconfig_bridge0="inet 192.168.7.1/24 addm tap0"
This is NOT "bridged" solution but "NAT" solution. Because tap0 is not bridged with my physical nic re0, but rather makes a separate virtual network with address space 192.168.7.1/24, as one can see above.
Along with that sysctl in /etc/sysctl.conf:
Code:
net.link.tap.up_on_open=1
Things work fine. This means, tap0 will go up when your VM boots up. That's where this sysctl comes into play...
Just one thing I noticed: with this approach tap0 has to be configured from the VM OS. And in case of Windows the virtio-net driver has to be installled first from inside the VM.

But that's not all there is. Because it is NATed, special routing must be accomplished for the VM to be connected to the outer world.
This is accomplished by this /etc/pf.conf:
Code:
set skip on lo0
set skip on tap0
nat on re0 from ! re0 to any -> (re0)
nat on bridge0 from any to 192.168.7.0/24 -> (bridge0)
nat on wlan0 from ! wlan0 to any -> (wlan0)

pass quick on bridge0 from any to any
pass quick on re0 from any to any
pass quick on wlan0 all
Because physically I have re0 (LAN) and wlan0 (Wifi AP) NICs.
NAT rules above just beautifully show what's happening with address translation between 2 networks: the "outer network" and the "NATed network" (my bridge0 in this case).

EDIT: having mentioned PF here, it needs to be enabled, along with its rules. Read man about rc.conf and PF.
 
my /etc/rc.conf

Code:
ifconfig_em0="DHCP"
local_unbound_enable="YES"
gateway_enable="YES"

/etc/sysctl.conf :

Code:
net.link.tap.up_on_open=1
net.inet.ip.forwarding=1
 
You're using vm-bhyve, hence configuration files will look different. The problems with vm-bhyve is that it is a "black box". I don't use it nor do I find it convenient for my purposes.
So... whatever it offers you for networking, take it or leave it. No help here.
 
are u telling that some hidden configuration settings are added by vm-bhyve and for this reason if I use a "manual" network configuration for starting a vm with bhyve,it will not work because the hidden configuration added by vm-bhyve ? I'm not sure that it is like this,because I have removed several times vm-bhyve and I tried to follow the instructions posted on the freebsd man page to configure correctly the networking for bhyve,but even in this case,it worked only 1 time,the first time I did it. Further tries to repeat the first success never worked. Even with a new reinstallation of freebsd.
 
are u telling that some hidden configuration settings are added by vm-bhyve and for this reason if I use a "manual" network configuration for starting a vm with bhyve,it will not work because the hidden configuration added by vm-bhyve ? I'm not sure that it is like this,because I have removed several times vm-bhyve and I tried to follow the instructions posted on the freebsd man page to configure correctly the networking for bhyve,but even in this case,it worked only 1 time,the first time I did it. Further tries to repeat the first success didn't work. Even with a new reinstallation of freebsd.
You use either the one or the other. Or it will be a mess.
And yes, whatever the vm-bhyve scripts do to create its "switch", I have NO IDEA. Nor is it documented anywhere, nor is anybody supposed to care, I think. It's a "lazy man's bhyve", I think. Well, to be respectful, it works fine for an average use case -- that's why it was created.
 
yes,sure. I agree. Point is that I want to always to know,under the limit of my abilities and understanding,what are the command lines that produce the result, to be able to repeat them as simply and clearly as possible in other situations. Science works like this.
 
Oh, you will learn soon :) . This stuff is not complicated... actually, in the end of it, your bhyve VM will either work or not. And if it doesn't... there isn't much you can do with a screw-driver to fix it :).
...BTW, did you manage to make your video cards passthrough to VM and work at that?
 
the time to configure the passthrough is not yet came. This is the tcpdump made on freebsd : paste.ubuntu.com/p/ghVdS56Y6f ; actually 1.7 is the IP assigned to ubuntu guest os : ibb.co/fkW04fx ; as u can see I can ping the ubuntu vm from freebsd... I will send an help request on the freebsd ML. Im not experienced but I feel that the problem is inside the ubuntu network configuration.
 
Talking about Ubuntu network configuration, I've always had problems whenever NetworkManager started to meddle. And it WILL start unless you explicitly disable it as a service though systemctl.
So generally my configuration was usually 'global' through /etc/network/interfaces file. And there configure STATIC address.
Another thought, Ubuntu may have some sort of firewall enabled. Some systemd startup script... Or some stupid default network configuration...
So! I would recommend to start by disabling NetworkManager (through systemctl command, of course).
 
You know, I just booted Ubuntu as bhyve guest and tried to set up networking there. OK, NetworkManager finally did activeate the NIC.
But I also had to edit /etc/resolv.conf and to set nameserver to something usable (8.8.8.8).

And my, I always forget that they dumped good old ifconfig. Instead you have to type something like ip address (that's exactly the command)... But the desktop looks cool.
 
It worked, I only booted it for testing purposes as a Live DVD.
But I gave up Linux some 5 years ago... after the introduction of systemd. Later I learned to use it, but... FreeBSD is less messy and more to my taste. Linux is becoming more and more of a black box thing.
 
yes,I understand perfectly what you mean. There are so many ways to reach the same goal and the error could be in a lot of places. And this make Linux more and more a toy for the geeks. I read that even Linus doesn't use it. Probably he knows that he has no time to spend tryng to understand what's wrong. Because everything can break iteself anytime,on Linux. But,don't tell this to the linux lovers,they will say that's not true. I've modified the file /etc/resolv.conf on Linux like this :

Code:
nameserver 8.8.8.8
options edns0 trust-ad
search homenet.telecomitalia.it

but nothing. If I ping 172.217.21.67 it says : destination host unreachable.
 
Well, how about firewall rules on your host (FreeBSD) machine? Without it VM will not be able to get Internet. And vm-bhyve wont' do that either.
 
I don't have any firewall installed. Can u do an "ifconfig" for me on FreeBSD ? I want to see how is a bhyve network configuration that works correctly. And tell me which commands you have issued on the terminal before to start the bhyve VM. I suspect that you haven't any netplan file. can u show your /etc/resolv.conf from linux ? can u make an ifconfig on linux ?
 
No, better YOU show your ifconfig on FreeBSD host. We'll see what networks you have. You mentioned that you could ping your Ubuntu VM? That means, mostly things work. You only need firewall rules to make your VM see internet.
My information won't help you at all because I'm using passthrough network card that is directly connected to LAN. So...
 
Back
Top