How to Set up a Raspberry Pi as a Wireless Access Point
Page 1 of 1
How to Set up a Raspberry Pi as a Wireless Access Point
How to Set up a Raspberry Pi as a Wireless Access Point
Gary Sims 2nd Feb 2014 Linux 43 Comments
The Raspberry Pi can connect to a Wi-Fi network using a USB dongle but using that same dongle you can also turn your Raspberry Pi into a wireless access point. Once set up correctly, this will allow other wireless devices to connect to your Pi and optionally you can route any traffic out through the Ethernet port and on to the internet (via the router from your ISP).
However, before looking at the steps needed to get this working, a word of warning. The configuration needed can be a little complex and if things don’t work as they should then troubleshooting the problem can be difficult. Also for this to work correctly, you need a WiFi USB dongle that can work as an access point. The best place to find information about your particular dongle and the Raspberry Pi is on the embedded Linux Raspberry Pi Wi-Fi adapters page.
To configure a hotspot requires several steps:
In this example, the wireless network will use the address range
sudo nano /etc/network/interfaces
Place a “#” sign in front of all the lines which mention
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
The bottom half of the file will now look something like this:
Now reboot.
sudo apt-get install isc-dhcp-server
You can safely ignore any errors about not being able to start the DHCP server at this point. Now edit its configuration file:
sudo nano /etc/dhcp/dhcpd.conf
Add a “#” character in front of the “
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
Remove the “#” sign in front of the “
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
At the bottom of the file add the following lines:
subnet 192.168.42.0 netmask 255.255.255.0 {
range 192.168.42.10 192.168.42.50;
option broadcast-address 192.168.42.255;
option routers 192.168.42.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
Exit from nano with “Ctrl + X”.
Make the wireless adapter the default for the DHCP request:
sudo nano /etc/default/isc-dhcp-server
Change “
Exit from nano with “Ctrl + X”.
Restart the DHCP server:
sudo service isc-dhcp-server restart
sudo apt-get install hostapd
Edit the hostapd configuration file and create a wireless network:
sudo nano /etc/hostapd/hostapd.conf
Add the following lines:
interface=wlan0
driver=nl80211
#driver=rtl871xdrv
ssid=MyPi
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=raspberry
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
This will create a password protected network called
Tell hostapd where to find its configuration file by setting the default location:
sudo nano /etc/default/hostapd
Remove the “#” in front of “
DAEMON_CONF="/etc/hostapd/hostapd.conf"
sudo nano /etc/sysctl.conf
Find the line which reads “
# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1
Run the following command to activate forwarding now:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Now turn the Pi into a router with the follow commands:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
And save the routing tables into the file “
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Edit “
sudo nano /etc/network/interfaces
And add the following line to the end of the file. This line will restore the routing table whenever the Pi is booted:
pre-up iptables-restore < /etc/iptables.ipv4.nat
You should now reboot your Pi and test the wireless access using a laptop, smartphone, tablet or other Wi-Fi enabled device.
You may have noticed that the "hostapd.conf" file had two "
First install the
sudo apt-get install iw
Now run the following command:
iw list
If the output of the command is "
Adafruit has a pre-compiled version of hostapd for the
wget http://www.adafruit.com/downloads/adafruit_hostapd.zip
unzip adafruit_hostapd.zip
sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG
sudo mv hostapd /usr/sbin
sudo chmod 755 /usr/sbin/hostapd
Gary Sims 2nd Feb 2014 Linux 43 Comments
The Raspberry Pi can connect to a Wi-Fi network using a USB dongle but using that same dongle you can also turn your Raspberry Pi into a wireless access point. Once set up correctly, this will allow other wireless devices to connect to your Pi and optionally you can route any traffic out through the Ethernet port and on to the internet (via the router from your ISP).
However, before looking at the steps needed to get this working, a word of warning. The configuration needed can be a little complex and if things don’t work as they should then troubleshooting the problem can be difficult. Also for this to work correctly, you need a WiFi USB dongle that can work as an access point. The best place to find information about your particular dongle and the Raspberry Pi is on the embedded Linux Raspberry Pi Wi-Fi adapters page.
To configure a hotspot requires several steps:
- Configure the wireless adapter with a static IP address
- Install and configure a DHCP server
- Install and configure the access point daemon
- Configure IP routing between the wireless and Ethernet
In this example, the wireless network will use the address range
- Code:
192.168.42.n
- Code:
192.168.1.n
Configure the wireless adapter with a static IP address
Edit “/etc/network/interfaces” and add the static IP address information for- Code:
wlan0
sudo nano /etc/network/interfaces
Place a “#” sign in front of all the lines which mention
- Code:
wlan0
- Code:
wpa
- Code:
allow hotplug wlan0
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
The bottom half of the file will now look something like this:
Now reboot.
Install and configure a DHCP server
Install the DHCP server:sudo apt-get install isc-dhcp-server
You can safely ignore any errors about not being able to start the DHCP server at this point. Now edit its configuration file:
sudo nano /etc/dhcp/dhcpd.conf
Add a “#” character in front of the “
- Code:
option domain-name
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
Remove the “#” sign in front of the “
- Code:
authoritative;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
At the bottom of the file add the following lines:
subnet 192.168.42.0 netmask 255.255.255.0 {
range 192.168.42.10 192.168.42.50;
option broadcast-address 192.168.42.255;
option routers 192.168.42.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
Exit from nano with “Ctrl + X”.
Make the wireless adapter the default for the DHCP request:
sudo nano /etc/default/isc-dhcp-server
Change “
- Code:
INTERFACES=""
- Code:
INTERFACES="wlan0"
Exit from nano with “Ctrl + X”.
Restart the DHCP server:
sudo service isc-dhcp-server restart
Install and configure the access point daemon
Install hostapd:sudo apt-get install hostapd
Edit the hostapd configuration file and create a wireless network:
sudo nano /etc/hostapd/hostapd.conf
Add the following lines:
interface=wlan0
driver=nl80211
#driver=rtl871xdrv
ssid=MyPi
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=raspberry
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
This will create a password protected network called
- Code:
MyPi
- Code:
raspberry
Tell hostapd where to find its configuration file by setting the default location:
sudo nano /etc/default/hostapd
Remove the “#” in front of “
- Code:
DAEMON_CONF
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Configure IP routing between the wireless and Ethernet
Edit “- Code:
/etc/sysctl.conf
sudo nano /etc/sysctl.conf
Find the line which reads “
- Code:
Uncomment the next line to enable packet forwarding for IPv4
# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1
Run the following command to activate forwarding now:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Now turn the Pi into a router with the follow commands:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
And save the routing tables into the file “
- Code:
/etc/iptables.ipv4.nat
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Edit “
- Code:
/etc/network/interfaces
sudo nano /etc/network/interfaces
And add the following line to the end of the file. This line will restore the routing table whenever the Pi is booted:
pre-up iptables-restore < /etc/iptables.ipv4.nat
You should now reboot your Pi and test the wireless access using a laptop, smartphone, tablet or other Wi-Fi enabled device.
Troubleshooting
Since this configuration is quite complex things can easily go wrong. If you run into trouble, double check all the configuration files. It is also worth power cycling the Pi as it is possible for the USB dongle to get into an undefined state.You may have noticed that the "hostapd.conf" file had two "
- Code:
driver=
- Code:
nl80211
- Code:
rtl871xdrv
First install the
- Code:
iw
sudo apt-get install iw
Now run the following command:
iw list
If the output of the command is "
- Code:
nl80211 not found
- Code:
rtl871xdrv
Adafruit has a pre-compiled version of hostapd for the
- Code:
rtl871xdrv
wget http://www.adafruit.com/downloads/adafruit_hostapd.zip
unzip adafruit_hostapd.zip
sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG
sudo mv hostapd /usr/sbin
sudo chmod 755 /usr/sbin/hostapd
Similar topics
» DNS Servers public access!
» Using Raspberry Pi To Create Home Automation! and access from anywhere online!
» Tesla The Race to Zero Point Free Energy
» Zero Point Technologies, Monoatomic Gold, and The Secret of Modern Alchemy
» Mandatory Access Control
» Using Raspberry Pi To Create Home Automation! and access from anywhere online!
» Tesla The Race to Zero Point Free Energy
» Zero Point Technologies, Monoatomic Gold, and The Secret of Modern Alchemy
» Mandatory Access Control
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|