Install the necessary packages - qemu(1), nmap(1), sudo(1) (or doas(1)). Sudo, (or doas) is necessary for running the virtual machines as these QEMU configurations open a separate console window through SDL. The examples in this book use sudo.
# pkg install qemu nmap sudo
Configure sudo as desired.
Create a directory layout for virtual machines and scripts, and download an install ISO for FreeBSD.
% mkdir -p ~/ipfw/VM ~/ipfw/SCRIPTS ~/ipfw/ISO % cd ~/ipfw/ISO % fetch https://download.freebsd.org/releases/amd64/amd64/ISO-IMAGES/<latest version>/FreeBSD-<latest-version>-RELEASE-amd64-dvd1.iso
Create the bridge and tap devices for the virtual machines (VMs) to use.
# ifconfig tap0 create # ifconfig tap1 create # sysctl net.link.tap.up_on_open=1 net.link.tap.up_on_open: 0 -> 1 # sysctl net.link.tap.user_open=1 net.link.tap.user_open: 0 -> 1 # ifconfig bridge0 create # ifconfig bridge0 addm tap0 addm tap1 addm hostintf <--- replace hostintf with host network interface (em0, bge0, etc.) # ifconfig bridge0 up
A script for creating and managing bridge and tap devices will be introduced in the next section.
Create two new VM image files and install FreeBSD on one.
% cd ~/ipfw/VM % qemu-img create -f qcow2 -o preallocation=full firewall.qcow2 8G % qemu-img create -f qcow2 -o preallocation=full external1.qcow2 8G % cd ~/ipfw/ISO % ln -s FreeBSD-<latest-version>-RELEASE-amd64-dvd1.iso fbsd.iso Copy the below text into a file (say, firewall.sh) and run: % sudo /bin/sh firewall.sh ------- #!/bin/sh # firewall.sh /usr/local/bin/qemu-system-x86_64 -monitor stdio \ -cpu qemu64 \ -vga std \ -m 4096 \ -smp 4 \ -cdrom ../ISO/fbsd.iso \ -boot order=cd,menu=on \ -blockdev driver=file,aio=threads,node-name=imgright,filename=../VM/firewall.qcow2 \ -blockdev driver=qcow2,node-name=drive0,file=imgright \ -device virtio-blk-pci,drive=drive0,bootindex=1 \ -netdev tap,id=nd0,ifname=tap0,script=no,downscript=no,br=bridge0 \ -device e1000,netdev=nd0,mac=02:69:70:66:77:00 \ -name \"Firewall\" exit -------
The FreeBSD installer should boot. Perform a standard installation of FreeBSD.
During the installation note the following:
Select to use UFS as the filesystem. ZFS does not perform well with small memory sizes.
In this Quick Start, use DHCP for networking. If desired, configure IPv6 if supported by the local LAN.
When adding the default user, ensure they are a member of the wheel group.
Once the installation completes, the virtual machine reboots into the newly installed FreeBSD image.
Login as root and update the system if desired.
Repeat the above step to create another QEMU script file, and perform another installation with these changes:
Copy the below text into a file (say, external1.sh) and run: % sudo /bin/sh external1.sh ------- #!/bin/sh # external1.sh /usr/local/bin/qemu-system-x86_64 -monitor stdio \ -cpu qemu64 \ -vga std \ -m 4096 \ -smp 4 \ -cdrom ../ISO/fbsd.iso \ -boot order=cd,menu=on \ -blockdev driver=file,aio=threads,node-name=imgleft,filename=../VM/external1.qcow2 \ -blockdev driver=qcow2,node-name=drive0,file=imgleft \ -device virtio-blk-pci,drive=drive0,bootindex=1 \ -netdev tap,id=nd0,ifname=tap1,script=no,downscript=no,br=bridge0 \ -device e1000,netdev=nd0,mac=02:20:65:78:74:31 \ -name \"External 1\" exit -------
As above, login and update the system if desired.
On both virtual machines (and all later installed VMs) , install the nmap(1) package. This brings in the version of ncat(1) used by scripts on the firewall and external VMs.
# pkg install nmap
Finally, download IPFW_root_bin.tgz file to both VMs. This tar file has a number of scripts needed for the virtual machines.
Move the tarzip file into /root and:
# mv IPFW_root_bin.tgz /root # # cd /root # # tar xvzf IPFW_root_bin.tgz ... files are extracted into /root/bin # # chmod +x /root/bin/*.sh
(End installation procedure.)