Quick guide on how to set up your laptop with FreeBSD as a router with internet access for your local area network (LAN).

When to use FreeBSD as a router.

You might have a LAN, that connect to the internet via a local gateway, such as an ADSL modem or other kind of internet gateway. If this gateway is down, such as cable problems or other ISP outage problems, and you have a laptop with FreeBSD and mobile network access through its wifi hotspot feature, then you can set up FreeBSD as a router with DHCP and have your LAN connect to internet via this.

Configure PF firewall for NAT.

Configure the PF firewall to enable network address translation (NAT). This is necessary for routing the data packets. The configuration below is a very simple firewall script. It assumes, that LAN interface is em0 and WAN interface in wlan0. You might want to secure and optimize it.

# nano /etc/pf.conf
nat on $wan from $lan:network to any -> ($wan)
pass all

Install and configure ISC DHCP server for LAN.

Install and configure ISC DHCP server for LAN. This will assign each device on the LAN to an IP address and set up internet access. The following configuration assumes, that the mobile network is on 192.168.1 and the new LAN will be on 192.168.2. It is also assumed, that Cencurfri DNS is used for DNS.

# pkg install isc-dhcp44-server
# nano /usr/local/etc/dhcpd.conf
default-lease-time 600;
max-lease-time 7200;
one-lease-per-client true;
option subnet-mask;
option broadcast-address;
option routers;
option domain-name-servers;
option domain-search "somedomain", "someotherdomain.dk";
subnet netmask
host somecomputer
  hardware ethernet 3d:4d:eb:0d:2d:22;
  option host-name "comecomputer.somedomain";

Configure network interfaces and services.

Configure network interfaces and services. The following examples assume, that the LAN interface will be em0.

# nano /etc/rc.conf
ifconfig_em0="inet netmask"

Configure IP address and hostname of known hosts.

If necessary, you can configure the IP address and hostname of known hosts on the LAN manually. This is optional and is not necessary for internet access.

# nano /etc/hosts
::1 localhost localhost.somedomain localhost localhost.somedomain somecomputer.somedomain somecomputer

Reboot and test.

Reboot and confirm, that everything works.

More about FreeBSD.

You can see more of my posts about FreeBSD in my FreeBSD category.