Multiple virtual network interfaces using netgraph

Load the ng_ether module, to make the real interfaces visible to netgraph

1
kldload ng_ether

or add it to /boot/loader.conf to load it on boot

1
echo 'ng_ether_load="YES"' >> /boot/loader.conf

Create the bridge and give it a name:

1
2
ngctl mkpeer em0: bridge lower link1
ngctl name em0:lower br0

Connect the physical interface to the bridge:

1
ngctl connect em0: br0: upper link2

Disable the overwriting of source route on the physical interface

1
ngctl msg em0: setautosrc 0

Enable promiscous mode on the physical interface

1
ngctl msg em0: setpromisc 1

Create the virtual interfaces and connect them to the bridge

1
2
ngctl mkpeer br0: eiface link3 ether
ngctl mkpeer br0: eiface link4 ether

Set an unique MAC-address to each of the virtual interfaces:

1
2
ifconfig ngeth0 link 00:5c:16:10:dd:79
ifconfig ngeth1 link 00:5c:16:10:dd:80