Turn your Raspberry Pi into a wireless access point

Wi-Fi-access-point-with-RaspberryPy

En a previous article talk about DietPi a system for our Raspberry Pi that in addition to having a large community has various systems and projects.

Among which you can turn your Raspberry Pi into a multimedia center, a retro game console, a NAS server among other things.

Now this time we will see how to use our Raspberry Pi as a wireless access point.

Turning Raspberry Pi into a wireless access point

In order to achieve this, It is necessary to have an operating system on our Raspberry, so the official system is perfect for it.

The first thing we must do is update our system, for this in a terminal we are going to type the following commands:

sudo apt-get update
sudo apt-get upgrade

Once this is done, we will restart our device, so that any changes made are saved.

Back in the system, let's proceed to install hostapd, dnsmasq and bridge-utils, These are the two programs that we will use to turn our Raspberry Pi into a wireless access point.

Therefore, to install it, just open a terminal and in it we are going to type the following commands.

sudo apt-get install hostapd
sudo apt-get install dnsmasq
sudo apt-get install bridge-utils

Configuration

Once the installation of these has been done, we are going to edit the configuration files of the programs so we must stop their services with:

sudo systemctl stop hostapd
sudo systemctl stop dnsmasq

Now we proceed to edit the following file:

sudo nano /etc/dhcpcd.conf

Now that it's in the file, add the following lines at the end:

interfaz wlan0
static ip_address = 192.168.0.10/24
denyinterfaces eth0
denyinterfaces wlan0

Here in this that we are placing, we are assuming we have local IP addressesIn addition, our network interface has common names and no others.

After that, press Ctrl + O, then Ctrl + X to save the file and exit the editor.

Configure DHCP server (dnsmasq)

We are going to use dnsmasq as our DHCP server. The idea of ​​a DHCP server is to dynamically distribute network configuration parameters, such as IP addresses, to interfaces and services.

Let's rename the default configuration file and write a new one:

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.back
sudo nano /etc/dnsmasq.conf

In the new file we are going to write these configuration lines:

interface=wlan0
dhcp-range=192.168.0.11,192.168.0.30,255.255.255.0,24h

The lines we add mean that we are going to provide IP addresses between 192.168.0.11 and 192.168.0.30 for the wlan0 interface. We close and save the file.

Y now we are going to create another new configuration file, we do this by typing the following command:

sudo nano /etc/hostapd/hostapd.conf

Inside it we will place the following:

interface=wlan0
bridge=br0
hw_mode=g
channel=5
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ssid=”Nombre-que-le-daras-a-tu-punto-de-acceso”
wpa_passphrase=”La-contraseña”

Where they will only edit the last two lines, because here they will place the name that they will give to their access point as well as their password, without the "".

Once edited we will save and close the changes. And now let's open the following file:

sudo nano /etc/default/hostapd

In this file, look for the line that says # DAEMON_CONF = ”” - remove that # and put the path to our configuration file in the quotes, so it looks like this:

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

Configure traffic forwarding

The idea here is that when they connect, the traffic is forwarded through their Ethernet cable. Therefore, we will have to send WLAN through an Ethernet cable to your modem. This involves editing another configuration file:

sudo nano /etc/sysctl.conf

Now find this line:

# net.ipv4.ip_forward = 1

And remove the "#", save and close to file.

The next step is to add a new iptables rule, then with:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
iptables-restore < /etc/iptables.ipv4.nat

Enable internet connection

Now the Raspberry Pi is acting as an access point that other devices can connect to. However, those devices still cannot use the Pi to access the internet. To make it possible, we need to build a bridge that passes all traffic between the wlan0 and eth0 interfaces.

We are ready to add a new bridge (called br0):

sudo brctl addbr br0

Next, we will connect the eth0 interface to our bridge:

sudo brctl addif br0 eth0

Finally, let's edit the interfaces file and add the following lines to the end of the file:

sudo nano /etc/network/interfaces
auto br0
iface br0 inet manual
bridge_ports eth0 wlan0

We reboot our Raspberry Pi and that's it.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   serjiuS said

    Good evening and thanks for the info.
    I have been able to get to the point "Configure traffic forwarding" the first two commands have been executed well but the third "iptables-restore </etc/iptables.ipv4.nat" did not.

    After this I have tried to continue and in the point "Enable the Internet connection" when I have executed the command "sudo brctl addif br0 eth0" I have run out of network in the rasperry, cable or wifi

    I have continued with the rest of the configuration locally, but after the restart I still have no network.

    Can it be fixed or reversed?

    Regards and thank you very much in advance.