Skip to content

How to set up Shareboxx with Ubiquiti Wifi for increased range

dividebysandwich edited this page May 5, 2024 · 2 revisions

image

Do you need more range? Are your neighbors complaining that the reception isn't good enough to download or upload large files? You might want to switch from a USB WiFi adapter to one or more Ubiquiti access points. This will require the use of a security gateway or a Ubiquity Dream Machine (UDM). Ideally you already have a full Ubiquiti setup in your home, then all you need to do is to follow these configuration steps.

We will create a new VLAN, put our raspberry pi into that VLAN, and then create a new WiFi network that is locked to that VLAN. In essence, Ubiquiti will replace the USB WiFi adapter and hostapd, the rest will be very similar.

Unifi setup

First, log into your UDM network management page, go to "Networks" (Not "WiFi"!) and create a new IP network:

image

In this example, we are using 192.168.4.1 as the IP of the Unifi Dream Machine. Our Raspi will have the IP 192.168.4.2 Settings of note: VLAN ID is 2, Isolate Network is enabled, DHCP is disabled. Also, you do not want to allow internet access.

Next, we'll set up a new wireless network:

image

Settings of note: Make sure the IP network is restricted to the VLAN we just created. Client device isolation should be enabled. You may want to use a password protected wifi until you are finished setting everything up.

If you have multiple Ubiquiti access points, you may want to select which AP the Shareboxx WiFi will be available if you have APs directed towards your neighbors, otherwise it will be broadcast from all APs.

Raspberry Pi Setup

This setup assumes that you have already set up a Raspberry Pi with Shareboxx, i.e. you ran "enable-captive-portal.sh", "setup-ssl.sh" and "setup-server.sh" from the "access-point" subdirectory of the shareboxx repository.

  1. Connect your Raspberry to the Ubiquiti UDM via Ethernet cable, and make sure it gets an IP address in your regular LAN.
  2. Disable any WiFi on your Raspberry.
  3. Disable or uninstall hostapd
  4. in /etc/rc.local, add the following:
ip link add link eth0 name eth2 type vlan id 2
ip addr add 192.168.4.2/24 dev eth2
ip link set up eth2
  1. In /etc/nginx/sites-available/shareboxx, change the server_name to 192.168.4.2
  2. Edit /etc/dnsmasq.conf to the following:
# Listening on the vlan interface
interface=eth2

# Pool of IP addresses served via DHCP (lease time of 24h)
dhcp-range=192.168.4.3,192.168.4.255,255.255.255.0,24h

# Redirect all domains (the #) to the address 192.168.4.2 (the server on the Pi)
address=/#/192.168.4.2
  1. Change iptables with the following commands as root:
iptables -F -t nat
iptables -F
iptables -t nat -I PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.4.2:3000
iptables -t nat -I PREROUTING -p tcp --dport 443 -j DNAT --to-destination 192.168.4.2:3443
iptables -A INPUT -p tcp --dport 22 -d 192.168.4.2 -j DROP
iptables -A INPUT -p tcp --dport 22 -i eth2 -j DROP
netfilter-persistent save
  1. Done!

You should now be able to connect to your Shareboxx WiFi which is being broadcast by your Ubiquiti access points, and the shareboxx captive portal should appear when you open a webbrowser or try to visit any webpage.