vm-bhyve: assign specific IP to vm

Thorny

Developer
Hello,

I want to assign a static IP to an FreeBSD guest in bhyve (using sysutils/vm-bhyve), but I failed. I assume it's about the context.

This is from host:
Code:
# ifconfig
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=209b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC>
        ether 90:1b:0e:cb:ce:37
        hwaddr 90:1b:0e:cb:ce:37
        inet 77.88.252.4 netmask 0xffffffc0 broadcast 77.88.252.63
My provider assigned my an additional IP like 84.130.41.117 and mask 255.255.255.248.

Currently I created a public switch with:
vm switch create public

Afterwards I added IP and mask in the guest in /etc/rc.conf. On boot it grabs the IP but it can't ping anything else nor reach the internet. How can I get the guest working with the IP?

Greetings,
Torsten
 
You will need at least a default gateway or else you will never be able to get out of the subnet. Only setting an IP address is not enough.
 
You will need at least a default gateway or else you will never be able to get out of the subnet. Only setting an IP address is not enough.
I did, but this does not change anything. Like here:
Bash:
# route add default 84.130.41.112
add net default: gateway 84.130.41.112
root@103legacy:~ # ping 77.88.252.4
PING ping 77.88.252.4 (ping 77.88.252.4): 56 data bytes
[nothing]
 
Where did you set this? It needs to be set on the VM, not the host. And did you also assign an uplink interface to the public switch?
 
Where did you set this? It needs to be set on the VM, not the host. And did you also assign an uplink interface to the public switch?
It was done in the VM, not the host!

Regarding your second question, i was under the impression, that vm-bhyve managed this by itself. After starting the VM i see a "vm-public" and "tap0" entry in ifconfig. Also in the VM there is a vnet0 network show by ifconfig.
However the additional IP is not listed in em0 of the host. But it also doesn't work if i assign it via em0_alias0 in /etc/rc.conf of host.
 
Regarding your second question, i was under the impression, that vm-bhyve managed this by itself.
Adding the various tap(4) interfaces from the VMs, yes. But how could it possibly know which interface to use to communicate with the outside world?

After starting the VM i see a "vm-public" and "tap0" entry in ifconfig. Also in the VM there is a vnet0 network show by ifconfig.
That simply means your VM is started and is correctly attached to the (virtual) switch. But your (virtual) switch isn't connected to anything else at the moment.

However the additional IP is not listed in em0 of the host. But it also doesn't work if I assign it via em0_alias0 in /etc/rc.conf of host.
It's not supposed to. Treat the VM like you would any other 'real' physical host because for all intents and purposes that's what a VM really is.


Here's my config:
Code:
root@hosaka:~ # vm switch list
NAME     TYPE      IFACE       ADDRESS  PRIVATE  MTU   VLAN  PORTS
servers  standard  vm-servers  -        no       9000  11    lagg0
public   standard  vm-public   -        no       9000  10    lagg0
Notice the lagg(4) interfaces? Those are on the host and tied to my physical network. This is the path the network takes when a VM talks to anything outside of that (virtual) switch.

Code:
root@hosaka:~ # ifconfig lagg0
lagg0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 9000
        options=8120b8<VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,WOL_MAGIC,VLAN_HWFILTER>
        ether 00:25:90:f1:58:39
        laggproto lacp lagghash l2,l3,l4
        laggport: igb1 flags=1c<ACTIVE,COLLECTING,DISTRIBUTING>
        laggport: igb2 flags=1c<ACTIVE,COLLECTING,DISTRIBUTING>
        groups: lagg
        media: Ethernet autoselect
        status: active
        nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>

At the moment you have a (virtual) switch attached to one or more (virtual) machines but not tied to anything else. So it's a "stand-alone" network.
 
Mh, I see the difference but I did not understand what to do. This is my output:
Code:
# vm switch list
NAME    TYPE      IFACE      ADDRESS  PRIVATE  MTU  VLAN  PORTS
public  standard  vm-public  -        no       -    -     -
What irritates me, is that this works fine at another computer, but not at the server.

Also I don't understand what I should do. Should I create a vlan and create a lagg with my em0 interface?
 
No, the vlan(4) and lagg(4) is specific to my situation.

Assuming the host is connected to the provider on the em0 interface you would need to do vm switch add public em0. That will tie the (virtual) switch to the physical interface em0. Any VM connected to your public switch will then be connected to the same physical network as the host.
 
Ah, now i see what i have missed before. :) Indeed you are right, there was no connection to the interface.

But sadly it still doesn't work. It got even more curious: if i set a default gateway my jail within the same subnet will lost its connection (while the vm still not having it).

Also i do not fully understand the switches from vm. If i use "vm switch address" and adding the IP i want the vm to use: will this work?
 
I'm sadly out of options and ideas how to solve the problem. :(
When using vm in an environment with DHCP enabled, it works just fine. But when using different subnets and static IP addresses i just don't get it.
 
your mask is wrong contact your ISP. You can't reach 84.130.41.112 as default gw as in this network the first address is 113.

Network: 84.130.41.112/29
Broadcast: 84.130.41.119
HostMin: 84.130.41.113
HostMax: 84.130.41.118
 
My ISP gave this information to me:
IP: 84.130.41.117
Mask: 255.255.255.248
[No gateway given]

Since I'm not that good with networks, i tried 84.130.41.112 and 84.130.41.113 as default route, but neither works. So i should use 113? What else did i wrong?
 
is this ppp / pppoe?

The first address in this network is 113.

You can check if you see some other hosts in this subnet 84.130.41.112/29 they should be accessible directly without the gateway. For the test you can set this address on vlan on your host and try to ping and see if you see any arp records.
 
I have no idea if it is ppp / pppoe. How can i know what is what?

I set the gateway to 113 and it still doesn't work.

I'm owning also 84.130.41.118, which is assigned to a jail at the same host. I can't ping it. Or anything else between 113 and 119.
 
It's not PPP or PPPoE. It's a typical hosting provider connection, plain ethernet, nothing fancy.
 
I would suggest trying to set the additional IP address on your host first, make sure that works. Only once you know the IP settings are correct, then try it on a jail.
 
Just tested: when i'm using the IP for a jail defined in /etc/jail.conf it works fine. If used the same config in the vm, it doesn't.
 
Back
Top