Raspberry pi точка доступа wifi

Set up your Raspberry Pi as wireless access point

A great and flexible way to connect remotely to your Raspberry Pi, especially when no networks are available, is to set it up as a wireless access point. This is not trivial, but below I guide you through the steps to set this up.

Table of contents

Getting started

In order to work as an access point, the Raspberry Pi will need to have access point software installed, along with DHCP server software to provide connecting devices with a network address.

To create an access point, we’ll need DNSMasq and HostAPD. Install all the required software in one go with this command:

sudo apt install dnsmasq hostapd 

Since the configuration files are not ready yet, we need to stop the new software from running:

sudo systemctl stop dnsmasq sudo systemctl stop hostapd 

Configure a static IP

We are configuring a standalone network to act as a server, so the Raspberry Pi needs to have a static IP address assigned to the wireless port. Here I assume we are using the standard 192.168.x.x IP addresses for our wireless network, so we will assign the server the IP address 192.168.4.1.

Читайте также:  Rt ac66u отваливается wifi

To configure the static IP address, edit the dhcpcd configuration file with:

Go to the end of the file and edit it so that it looks like the following:

interface wlan0 static ip_address=192.168.4.1/24 nohook wpa_supplicant 

Now restart the dhcpcd daemon and set up the new wlan0 configuration:

sudo service dhcpcd restart 

Configure the DHCP server

The DHCP service is provided by dnsmasq . Let’s backup the old configuration file and then create a new one:

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

Type the following information into the dnsmasq configuration file and save it:

interface=wlan0 dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h 

This will provide IP-addresses between 192.168.4.2 and 192.168.4.20 with a lease time of 24 hours. Now start dnsmasq to use the updated configuration:

sudo systemctl start dnsmasq 

Configure the access point host software

Now it is time to configure the access point software:

sudo nano /etc/hostapd/hostapd.conf 

Add the below information to the configuration file:

country_code=DE interface=wlan0 ssid=YOURSSID channel=9 auth_algs=1 wpa=2 wpa_passphrase=YOURPWD wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP CCMP rsn_pairwise=CCMP 

Make sure to change the ssid and wpa_passphrase . We now need to tell the system where to find this configuration file. Open the hostapd file:

sudo nano /etc/default/hostapd 

Find the line with #DAEMON_CONF , and replace it with this:

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

Start up the wireless access point

Run the following commands to enable and start hostapd:

sudo systemctl unmask hostapd sudo systemctl enable hostapd sudo systemctl start hostapd 

Enable routing and IP masquerading

You may want devices connected to your wireless access point to access the main network and from there the internet. To do so, we need to set up routing and IP masquerading on the Raspberry Pi. We do this by editing the sysctl.conf file:

Читайте также:  Win 10 пропадает сеть wifi

And uncomment the following line:

Next we need a “masquerade” firewall rule such that the IP-addresses of the wireless clients connected to the Raspberry Pi can be substituted by their own IP address on the local area network. To do so enter:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE 

Now to save these firewall rules and automatically use them upon boot, we will use the netfilter-persistent service:

sudo netfilter-persistent save 

Once rebooted, if you go to another device that has wireless and search for wireless networks you should be able to see your wireless access point and be able to connect to it using the credentials that you configured.

Stop the access point

First stop the hostadp service:

sudo systemctl stop hostap 

and comment out the lines related to the static IP address. Now reboot

Comments

There are currently not any comments yet.

Add a Comment

Please leave your comment below. If you’d like to be notified of my reply, please leave your comment here for others but also send your comment as an email to me. I will try to reply as soon as I can. Thanks!

Источник

Raspberry Pi 3 в качестве точки достпупа WiFi

Как известно Raspberry Pi 3 имеет встроенную карту WiFi. Почему бы, в таком случае, не делать из Малинки точку доступа?
Нам потребуется установит пакеты hostapd – это сама точка доступа, и isc-dhcp-server – dhcp-сервер, который будет у нас раздавать настройки ip-адресов для беспроводных устройств.
Подключаемся к Raspberry и в терминале вводим следующие команды:

sudo apt-get update sudo apt-get install hostapd isc-dhcp-server

После установки отредактируем некоторые файлы. Начнем с сервера dhcp.

Читайте также:  Самсунг галакси 4 нет вайфая

1. Настройка сервера DHCP

sudo nano /etc/dhcp/dhcpd.conf

#option domain-name “example.org”;
#option domain-name-servers ns1.example.org, ns2.example.org;

И, наоборот раскомментируем следующее значение:
authoritative;

Далее, в самом конце файла добавляем следующее:

subnet 192.168.100.0 netmask 255.255.255.0

Сохраняем файл.
Теперь нам надо указать при обращении к какому интерфейсу будут выдаваться адреса для клиентов. У нас это беспроводной интерфейс wlan0.

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

находим параметр INTERFACES=”” и меняем на INTERFACES=”wlan0″

2. Настройка беспроводного интерфейса

sudo nano /etc/network/interfaces
iface wlan0 inet static address 192.168.100.1 netmask 255.255.255.0

3. Настройка точки доступа

Создадим и отредактируем конфигурационный файл для точки доступа

sudo touch /etc/hostapd/hostapd.conf sudo nano /etc/hostapd/hostapd.conf

Вставим следующее содержимое:

interface=wlan0 driver=rtl871xdrv ssid=Raspberry_AP hw_mode=g channel=6 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=PaSsWoRd wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP

ssid= имя сети, wpa_passphrase= пароль для подключения

4. Настройка NAT

Теперь осталось сделать так, чтобы на подключаемых устройствах появился интернет.

Найдем и раскомментируем строку net.ipv4.ip_forward=1

Сохраняем и закрываем файл.

Далее, создадим правила iptables для организации раздачи интернет.

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
sudo sh -c "iptables-save > /etc/iptables.rules"

Добавим в автозагрузку правила iptables

Идем в самый конец файла и перед exit 0 добавим строку:

Перегружаем Raspberry и смотрим на устройствах заработало или нет.

Если не работает – проверяем что именно не запускается.

sudo service hostapd status sudo service isc-dhcp-server status

Источник

Оцените статью
Adblock
detector