Install required packages
- rfkill: a wireless utility
- zd1211-firmware: common firmware that works with many Wi-Fi dongles
- hostapd: the hostap wireless access point daemon
- hostap-utils: supplemental hostap tools
- iw: wireless configuration utility
- dnsmasq: DHCP and DNS utility
- bridge-utils: used for connecting multiple Ethernet devices together
1 2 3 4 5 6 7 |
sudo apt-get install rfkill sudo apt-get install zd1211-firmware sudo apt-get install hostapd sudo apt-get install hostap-utils sudo apt-get install iw sudo apt-get install dnsmasq sudo apt-get install bridge-utils |
Getting WiFi adapter running
Check that the RPi recognizes the Wi-Fi dongle.
1 |
lsusb |
or
1 2 3 4 5 6 7 8 9 10 |
dmesg | more [...] [ 3.332562] usb 1-1.3: new high-speed USB device number 4 using dwc_otg [ 3.460482] usb 1-1.3: New USB device found, idVendor=148f, idProduct=5370 [ 3.469467] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 3.478748] usb 1-1.3: Product: 802.11 n WLAN [ 3.484982] usb 1-1.3: Manufacturer: Ralink [ 3.490964] usb 1-1.3: SerialNumber: 1.0 [...] |
Verify that the Wi-Fi dongle supports AP mode
1 |
iw list |
Configure the Wireless Interface
Make a backup of /etc/network/interfaces and then open it in a text editor:
1 2 |
sudo cp /etc/network/interfaces /etc/network/interfaces.orig sudo nano /etc/network/interfaces |
edit /etc/network/interfaces as below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
auto lo auto br0 iface lo inet loopback iface eth0 inet dhcp allow-hotplug wlan0 allow-hotplug eth0 iface wlan0 inet manual iface br0 inet dhcp bridge_fd 1 bridge_hello 3 bridge_maxage 10 bridge_stp off bridge_ports eth0 wlan0 |
Restart the wlan0 interface:
1 2 |
sudo ifdown wlan0 sudo ifup wlan0 |
Configure hostapd Settings
1 2 |
sudo cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.orig sudo nano /etc/hostapd/hostapd.conf |
edit /etc/hostapd/hostapd.conf as below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
interface=wlan0 bridge=br0 #driver=rtl871xdrv country_code=IT ctrl_interface=wlan0 ctrl_interface_group=0 ssid=RPiAP hw_mode=g channel=1 wpa=3 wpa_passphrase=password wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP beacon_int=100 auth_algs=3 macaddr_acl=0 wmm_enabled=1 eap_reauth_period=360000000 |
1 2 |
sudo cp /etc/default/hostapd /etc/default/hostapd.orig sudo nano /etc/default/hostapd |
configure
1 2 3 |
[...] DAEMON_CONF="/etc/hostapd/hostapd.conf" [...] |
1 2 |
sudo service networking restart sudo service hostapd restart |
Configure dnsmasq Settings
1 2 |
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.orig sudo nano /etc/dnsmasq.conf |
configure /etc/dnsmasq.conf with
1 2 3 |
domain-needed interface=wlan0 dhcp-range=192.168.2.1,192.168.2.254,12h |
After saving the file, you can easily verify all the settings were correct with the following command (it just parses out the comments and blank lines):
1 |
cat /etc/dnsmasq.conf | grep -v "#" | sed '/^$/d' |
Restart the dnsmasq service to apply the settings:
1 |
sudo service dnsmasq restart |
Enable Forwarding to Reach the Internet
Enable IPv4 forwarding
1 |
sudo sysctl -w net.ipv4.ip_forward=1 |
Enable NAT
1 |
sudo iptables -t nat -A POSTROUTING -j MASQUERADE |