By 苏剑林 | April 12, 2016
The Raspberry Pi 3, released in early March, comes with built-in Wi-Fi and Bluetooth. Combined with its existing Ethernet port, it has essentially become a wireless router. I couldn't resist getting one, intending to use it as both a router and a NAS. There are already many tutorials on using a Raspberry Pi as a router, though most are based on the Raspberry Pi 2. Versions prior to the 3 did not have built-in Wi-Fi, requiring an external wireless adapter. The Raspberry Pi 3 makes configuration much more convenient since Wi-Fi is integrated. I successfully configured it by referring to two foreign tutorials and am recording the process here.
Reference tutorials:
https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/
https://gist.github.com/Lewiscowles1986/fecd4de0b45b2029c390#file-rpi3-ap-setup-sh
The main software packages used are hostapd and dnsmasq:
Then, add the following to the end of /etc/dnsmasq.conf (modify the IP and network segment yourself; this file already exists with detailed configuration examples, but all lines are commented out with #):
interface=wlan0
dhcp-range=10.0.0.2,10.0.0.5,255.255.255.0,12h
Next, create a new file /etc/hostapd/hostapd.conf and add:
interface=wlan0
hw_mode=g
channel=10
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
wpa_passphrase=wifi_password
ssid=wifi_name
Then modify /etc/sysctl.conf and change (if this line exists, just remove the #):
net.ipv4.ip_forward=1
Finally, add the following script before exit 0 in /etc/rc.local:
After rebooting, you should see the hotspot. It's much simpler! The Wi-Fi signal strength of the Raspberry Pi is similar to the once-famous WR703N router toy.
I also configured offline downloading, NAS, automatic cloud synchronization, and more. Being unfamiliar with Linux, I fell into many traps. I want to remind everyone that many commands on the Raspberry Pi require sudo, and sudo on the Raspberry Pi does not require a password. However, with and without sudo are two completely different environments (two different users). For example, after running sudo screen -S sync, you won't see it when running screen -ls; you must run sudo screen -ls to see it. Additionally, if you add commands to /etc/rc.local, they are executed as sudo by default (whether or not you include sudo). I added a screen task there and couldn't find it with screen -ls no matter what I tried, only to realize I needed sudo screen -ls... Also, when running autossh for intranet penetration, you must include a sleep 5 command before autossh, otherwise autossh won't work even if it runs.
These were all pitfalls I spent a whole day jumping into.