Configure WiFi to Ethernet Router

This guide assumes you have already configured WiFi for your router.

Next, we configure the ethernet interface to provide network address translation for our client:

First, in the hypervisor, we configure the proper interfaces:

# cat /etc/hostname.if0
inet 192.168.30.1 255.255.255.0
up

Replace if0 with your actual ethernet device. We are going to assign all clients reserved IPs from the subnet 192.168.30.0/24.

Make sure to restart networking for this device:

# sh /etc/netstart if0

Next, we enable routing:

# sysctl net.inet.ip.forwarding=1
# echo "net.inet.ip.forwarding=1" >> /etc/sysctl.conf
# sysctl net.inet6.ip6.forwarding=1
# echo "net.inet6.ip6.forwarding=1" >> /etc/sysctl.conf

Next, we configure dhcpd:

# cat /etc/dhcpd.conf                                             
option domain-name "example.com";

subnet 192.168.30.1 netmask 255.255.255.0 {
        option routers 192.168.30.1;
        option domain-name-servers 192.168.30.1;
        range 192.168.30.2 192.168.30.254;
}
# rcctl enable dhcpd
# rcctl set dhcpd flags if0
# rcctl start dhcpd

You will need to either configure a caching nameserver on the host that listens to address 192.168.30.1, or choose a free public DNS service.

Finally, because we are using network address translation, we need to add a rule to packet filter:

match out on egress from !(egress:network) to any nat-to (egress:0)

Then reload the ruleset:

# pfctl -f /etc/pf.conf

Troubleshooting

If networking does not work immediately, try a reboot to ensure that all networking changes were properly applied.