How to setup your Raspberry Pi as an Access Point

Share on Facebook1Share on Google+0Tweet about this on TwitterShare on Reddit4Share on StumbleUpon0Pin on Pinterest0

About: Setting up your Raspberry Pi as an access point may come in handy. Especially in a pinch when your home router dies and you need some WiFi in your house while a new router is on order. It can also be useful if you want to set up an access point to perform evil doings like monitoring all the traffic or setting up an evil twin network.

In this tutorial we will be setting up a WiFi Access Point and linking all data to our Ethernet connection, so make sure we have an active internet connection on the Ethernet port to tunnel all the WiFi data to it.

Objective: To create a WiFi access point on our Raspberry Pi and link our WiFi connection to the Ethernet connection.

Material: You will need the following:

Instructions: Just a warning before continuing, setting up your network settings can mess things up if you are using the Raspberry Pi for something else. Be sure to make a backup of your Raspberry Pi before continuing if you need to. Also troubleshooting network issues can be difficult if you are inexperienced with networking. Be sure to follow the directions carefully and you should be alright.

We will begin by configuring our wireless adapter to a Static IP. We need it to be a static IP for our DHCP settings. Our WiFi IP addresses will have a range of 192.168.42.x (x is 2-254) and our ethernet will have an IP address range of 192.168.1.x (x is 2-254)

We will begin by setting up the static IP for wlan0 ( our wireless adapter, you can find your wireless adapter interface by typing in ‘iwconf’). Let’s edit our ‘/etc/network/interfaces’ file.

Your file should look similar to mine. We will need to add some lines and comment a few lines out.

Original /etc/network/interfaces configuration
Original /etc/network/interfaces configuration

We will need to comment out the last 3 lines. To comment out a line simply add a hashtag (#) in front of it. Next we need to add the following lines to setup our wlan0 to be a Static IP

The first line tells the configuration file that wlan0 will be a static IP. The address line is the static IP we want to use for our wireless adapter. The netmask is the same as our subnet and just tells the configuration what subnet we will be using. The gateway is our router IP address from the ethernet connection. Your configuration file should look similar to mine when you are done. Remember to save this file by typing CTRL + X and selecting Yes to save.

Our /etc/network/interfaces configuration after adding the static IP
Our /etc/network/interfaces configuration after adding the static IP

Now we can continue with installing the DHCP server. We will be using ‘isc-dhcp-server’ for our DHCP. Install it using the following command

You may see some errors after it finishes installing. That is okay since it has not been configured yet.

This error is expected since our DHCP configuration has not been setup.
This error is expected since our DHCP configuration has not been setup.

We can now configure our DHCP configuration file. Lets open up the configuration file using the following command:

We need to comment out the example option domain-name and domain-name-servers line. Remember to comment out a line simply add a ‘#’ in front of it.

Remove the ‘#’ comment from the ‘authoritative;’ line so that it looks like this:

Finally add the following lines to the bottom of your configuration file.

This will set up our DHCP server. We are setting up our server to on the 192.168.42.0 subnet. The second line means that our server will be serving IP addresses from 192.168.42.10 to 192.168.42.50. This means that we have 40 IP addresses to handout. It will lease an IP address for 600 seconds if the client doesn’t ask for specific time frame. Otherwise the maximum (allowed) lease will be 7200 seconds. The server will also ‘advise’ the client that it should use 255.255.255.0 as its subnet mask, 192.168.42.255 as its broadcast address, 192.168.42.1 as the router/gateway and 8.8.8.8 and 8.8.4.4 as its DNS servers. The DNS servers are from Google and are most commonly used.

Save this file by typing CTRL + X and selecting Yes to save.

We now need to configure the wireless adapter interface to be the default interface in the DHCP server. Open up this configuration file with the following command:

Change “INTERFACES=””” to “INTERFACES=”wlan0″”. Save this file by typing CTRL + X and selecting Yes to save.

We are now ready to install our Access Point software. We will be using ‘hostapd’. Install it using the following command:

Now we can configure our Access Point. We have 2 options. We can make it an open network or we can put a password on it and use WPA2 security. Nevertheless, lets open up the configuration using the following command: (Note: This file may not exist and may be empty, this is okay.)

For WPA2 security add the following:

For an Open network add the following:

Remember to only use one of the above. These will create an Access Point with the SSID of ‘Kamil’s Lab’ running on Channel ‘6’. If you chose the WPA2 method, the password is ‘dayz’. You can edit these lines as you see fit.

Also please note the driver line for the WPA2 configuration. The current configuration should work if you are using the Panda WiFi USB adapter like I am, if not try using the other wireless adapter driver. Save this file by typing CTRL + X and selecting Yes to save.

We will now configure hostapd and tell it where the file we created earlier is located. Run the following command:

Remove the ‘#’ in front of ‘DAEMON_CONF’ and alter the line to read:

Save this file by typing CTRL + X and selecting Yes to save.

Excellent, hostapd is now configured and we are almost done, we just need to configure the routing between our Wireless Adapter and our Ethernet.

We will begin by enabling IP forwarding. Type the following command:

Find the line which reads ‘Uncomment the next line to enable packet forwarding for IPv4' and uncomment the next line like this:

Save this file by typing CTRL + X and selecting Yes to save.

Now we will setup the IP Tables to make it mimic a router. Type the following commands:

We will now save the routing tables into the file ‘/etc/iptables.ipv4.nat’

We will need to edit our interfaces configuration one last time and add one last line so that the IP Tables commands take action every time we reboot. Open the configuration using the following command:

Now add the following line after the gateway line we added earlier. It must be after the gateway line or you will get an error when your Raspberry Pi boots.

That’s it! We can now reboot using the ‘reboot‘ command. Once the Raspberry Pi has rebooted we need to start the DHCP and Hostapd services using the following commands:

 

If you have any questions or need some help post a comment below and I’ll try to help you out.

Share on Facebook1Share on Google+0Tweet about this on TwitterShare on Reddit4Share on StumbleUpon0Pin on Pinterest0

2 Comments

Leave a Reply