0 Google+ 0 Reddit 4 StumbleUpon 0 Pinterest 0

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:

Raspberry Pi (I have PwnPi 3.0 running on mine, but this can be done using Raspbian)

USB WiFi Adapter – I use the Panda USB WiFi adapter

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.

nano /etc/network/interfaces 1 nano / etc / network / interfaces

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

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

iface wlan0 inet static address 192.168.42.1 netmask 255.255.255.0 gateway 192.168.1.1 1 2 3 4 iface wlan0 inet static address 192.168.42.1 netmask 255.255.255.0 gateway 192.168.1.1

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.

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

apt-get install isc-dhcp-server 1 apt - get install isc - dhcp - server

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

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

nano /etc/dhcp/dhcpd.conf 1 nano / etc / dhcp / dhcpd . conf

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.

#option domain-name "example.org"; #option domain-name-servers ns1.example.org, ns2.example.org; 1 2 #option domain-name "example.org"; #option domain-name-servers ns1.example.org, ns2.example.org;

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

# If this DHCP server is the official DHCP server for the local # network, the authoritative directive should be uncommented. authoritative; 1 2 3 # If this DHCP server is the official DHCP server for the local # network, the authoritative directive should be uncommented. authoritative ;

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

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; } 1 2 3 4 5 6 7 8 9 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 ; }

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:

nano /etc/default/isc-dhcp-server 1 nano / etc / default / isc - dhcp - server

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:

apt-get install hostapd 1 apt - get install hostapd

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.)

nano /etc/hostapd/hostapd.conf 1 nano / etc / hostapd / hostapd . conf

For WPA2 security add the following:

interface=wlan0 #driver=nl80211 driver=rtl871xdrv ssid=Kamil's Lab hw_mode=g channel=6 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=dayz wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP 1 2 3 4 5 6 7 8 9 10 11 12 13 14 interface = wlan0 #driver=nl80211 driver = rtl871xdrv ssid = Kamil ' s Lab hw_mode = g channel = 6 macaddr_acl = 0 auth_algs = 1 ignore_broadcast_ssid = 0 wpa = 2 wpa_passphrase = dayz wpa_key_mgmt = WPA - PSK wpa_pairwise = TKIP rsn_pairwise = CCMP

For an Open network add the following:

interface=wlan0 ssid=Kamil's Lab hw_mode=g channel=6 auth_algs=1 wmm_enabled=0 1 2 3 4 5 6 interface = wlan0 ssid = Kamil ' s Lab hw_mode = g channel = 6 auth_algs = 1 wmm_enabled = 0

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:

nano /etc/default/hostapd 1 nano / etc / default / hostapd

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

DAEMON_CONF="/etc/hostapd/hostapd.conf" 1 DAEMON_CONF = "/etc/hostapd/hostapd.conf"

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:

nano /etc/sysctl.conf 1 nano / etc / sysctl . conf

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

# Uncomment the next line to enable packet forwarding for IPv4 net.ipv4.ip_forward=1 1 2 # Uncomment the next line to enable packet forwarding for IPv4 net . ipv4 . ip_forward = 1

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:

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 1 2 3 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

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

sh -c "iptables-save > /etc/iptables.ipv4.nat" 1 sh - c "iptables-save > /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:

nano /etc/network/interfaces 1 nano / etc / network / interfaces

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.

pre-up iptables-restore < /etc/iptables.ipv4.nat 1 pre - up iptables - restore < / etc / iptables . ipv4 . nat

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:

service hostapd start service isc-dhcp-server start 1 2 service hostapd start service isc - dhcp - server start

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