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
lan="em0"
wan="wlan0"
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 255.255.255.0;
option broadcast-address 192.168.2.255;
option routers 192.168.2.1;
option domain-name-servers 89.233.43.71;
option domain-search "somedomain", "someotherdomain.dk";
authoritative;
subnet 192.168.2.0 netmask 255.255.255.0
{
  range 192.168.2.100 192.168.2.199;
}
host somecomputer
{
  hardware ethernet 3d:4d:eb:0d:2d:22;
  fixed-address 192.168.2.2;
  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 192.168.2.1 netmask 255.255.255.0"
gateway_enable="YES"
pf_enable=YES"
pf_rules="/etc/pf.conf"
pf_flags=""
dhcpd_enable="YES"
dhdpd_ifaces="em0"

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
127.0.0.1 localhost localhost.somedomain
192.168.2.2 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.