How to Bake an Onion Pi

I’ve always been kinda lazy or convenient I see no use of re-inventing the wheel again and found a great guide in how to make an onion pi from

Once downloaded the script file an unpacked and ran it.

There it should work but i was using a ralink 5370 usb wifi dongle so no joy at all since the guide was based on another brand.

I actually had to open script and a make a few modifications.

But the script that is working is pasted here.

# Based on Adafruit Learning Technologies Onion Pi project
# More info:

if (( $EUID != 0 )); then
echo ”This must be run as root. Try ‘sudo bash $0′.”
exit 1
echo ”
$(tput setaf 2)              .~~.   .~~.
$(tput setaf 6)   /         $(tput setaf 2)’. \ ‘ ‘ / .’$(tput setaf 6)         \
$(tput setaf 6)  |   /       $(tput setaf 1).~ .~~~..~.$(tput setaf 6)      \   |
$(tput setaf 6) |   |   /  $(tput setaf 1) : .~.’~’.~. :$(tput setaf 6)   \   |   |
$(tput setaf 6)|   |   |   $(tput setaf 1)~ (   ) (   ) ~$(tput setaf 6)   |   |   |
$(tput setaf 6)|   |  |   $(tput setaf 1)( : ‘~’.~.’~’ : )$(tput setaf 6)   |  |   |
$(tput setaf 6)|   |   |   $(tput setaf 1)~ .~ (   ) ~. ~ $(tput setaf 6)  |   |   |
$(tput setaf 6) |   |   \   $(tput setaf 1)(  : ‘~’ :  )$(tput setaf 6)   /   |   |
$(tput setaf 6)  |   \       $(tput setaf 1)’~ .~~~. ~’$(tput setaf 6)       /   |
$(tput setaf 6)   \              $(tput setaf 1)’~’$(tput setaf 6)          /
$(tput bold ; tput setaf 4)         Raspberry PiFi$(tput sgr0)

echo ”$(tput setaf 6)This script will configure your Raspberry Pi as a wireless access point.$(tput sgr0)”
read -p ”$(tput bold ; tput setaf 2)Press [Enter] to begin, [Ctrl-C] to abort…$(tput sgr0)”

echo ”$(tput setaf 6)Updating packages…$(tput sgr0)”
apt-get update -q -y

echo ”$(tput setaf 6)Installing hostapd…$(tput sgr0)”
apt-get install hostapd

echo ”$(tput setaf 6)Installing ISC DHCP server…$(tput sgr0)”
apt-get install isc-dhcp-server

echo ”$(tput setaf 6)Configuring ISC DHCP server…$(tput sgr0)”
cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.bak
sed -i -e ‘s/option domain-name ””/# option domain-name ””/g’ /etc/dhcp/dhcpd.conf
sed -i -e ‘s/option domain-name-servers option domain-name-servers’ /etc/dhcp/dhcpd.conf
sed -i -e ‘s/#authoritative;/authoritative;/g’ /etc/dhcp/dhcpd.conf
echo -e ”subnet netmask {
option broadcast-address;
option routers;
default-lease-time 600;
max-lease-time 7200;
option domain-name \042local\042;
option domain-name-servers,;
}” >> /etc/dhcp/dhcpd.conf
cp /etc/default/isc-dhcp-server /etc/default/isc-dhcp-server.bak
sed -i -e ‘s/INTERFACES=””/INTERFACES=”wlan0″/g’ /etc/default/isc-dhcp-server

echo ”$(tput setaf 6)Turning off wlan0 if active…$(tput sgr0)”
ifdown wlan0

echo ”$(tput setaf 6)Updating network interfaces…$(tput sgr0)”
mv /etc/network/interfaces /etc/network/interfaces.bak
echo ”auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0

iface wlan0 inet static
” > /etc/network/interfaces

echo ”$(tput setaf 6)Assigning static IP address…$(tput sgr0)”
ifconfig wlan0

echo ”$(tput setaf 6)Configuring hostapd…$(tput sgr0)”
echo ”$(tput bold ; tput setaf 2)Type a 1-32 character SSID (name) for your PiFi network, then press [ENTER]:$(tput sgr0)”
read ssid
echo ”$(tput setaf 6)PiFi network SSID set to $(tput bold)$ssid$(tput sgr0 ; tput setaf 6). Edit /etc/hostapd/hostapd.conf to change.$(tput sgr0)”

until [ $pwd1 == $pwd2 ]; do
echo ”$(tput bold ; tput setaf 2)Type a password to access your PiFi network, then press [ENTER]:$(tput sgr0)”
read -s pwd1
echo ”$(tput bold ; tput setaf 2)Verify password to access your PiFi network, then press [ENTER]:$(tput sgr0)”
read -s pwd2

if [ $pwd1 == $pwd2 ]; then
echo ”$(tput setaf 6)Password set. Edit /etc/hostapd/hostapd.conf to change.$(tput sgr0)”

echo ”interface=wlan0
rsn_pairwise=CCMP” > /etc/hostapd/hostapd.conf

echo ”$(tput setaf 6)Setting hostapd to run at system boot…$(tput sgr0)”
cp /etc/default/hostapd /etc/default/hostapd.bak
sed -i -e ‘s/#DAEMON_CONF=””/DAEMON_CONF=”\/etc\/hostapd\/hostapd.conf”/g’ /etc/default/hostapd

echo ”$(tput setaf 6)Setting IP forwarding to start at system boot…$(tput sgr0)”
cp /etc/sysctl.conf /etc/sysctl.bak
echo ”net.ipv4.ip_forward=1″ >> /etc/sysctl.conf

echo ”up iptables-restore < /etc/iptables.ipv4.nat” >> /etc/network/interfaces

echo ”$(tput setaf 6)Activating IP forwarding…$(tput sgr0)”
sh -c ”echo 1 > /proc/sys/net/ipv4/ip_forward”

echo ”$(tput setaf 6)Setting up IP tables to interconnect ports…$(tput sgr0)”
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o wlan0 -m state –state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

echo ”$(tput setaf 6)Saving IP tables…$(tput sgr0)”
sh -c ”iptables-save > /etc/iptables.ipv4.nat”
echo ”$(tput setaf 6)Starting hostapd service…$(tput sgr0)”
service hostapd start

echo ”$(tput setaf 6)Starting ISC DHCP server…$(tput sgr0)”
service isc-dhcp-server start

echo ”$(tput setaf 6)Checking hostapd status…$(tput sgr0)”
service hostapd status

#if [ $hostapd_result == 3 ]; then
# echo ”ERROR: hostapd start failed.”
# exit 1

echo ”$(tput setaf 6)Checking ISC DHCP server status…$(tput sgr0)”
service isc-dhcp-server status

#if [ $dhcp_result == 3 ]; then
# echo ”ERROR: ISC DHCP server failed to start.”
# exit 1

echo ”$(tput setaf 6)Setting hostapd to start on system boot…$(tput sgr0)”
update-rc.d hostapd enable

echo ”$(tput setaf 6)Setting ISC DHCP server to start on system boot…$(tput sgr0)”
update-rc.d isc-dhcp-server enable

echo ”$(tput setaf 6)Removing WPASupplicant…$(tput sgr0)”
mv /usr/share/dbus-1/system-services/fi.epitest.hostap.WPASupplicant.service ~/

echo ”$(tput setaf 6)Rebooting…$(tput sgr0)”

exit 0

After reboot service isc-dhcp-server will probably have error message to have that fixed enter

sudo nano /etc/default/ifplugd

and change INTERFACES=”auto”



exit with ctrl-x and choose save.

This guide is based on

Reboot and you should be good to go.

Good Luck !!



Spara naturen laga istället för att slänga