Rispondi 
GUIDA PRIMA INSTALLAZIONE Raspberry ed OpenPlotter (Agg. 23/03)
Autore Messaggio
Capitan Papino Offline
Senior utente

Messaggi: 2.850
Registrato: Sep 2010 Online
Messaggio: #80
RE: GUIDA PRIMA INSTALLAZIONE Raspberry ed OpenPlotter (Agg. 23/03)
sto cercando di configurare il RPI come access point e ho trovato il seguente articolo:

"Using your new Raspberry Pi 3 as a WiFi access point with hostapd
04 March 2016 on wifi, raspberrypi, hostapd, softap
There's a new Raspberry Pi. This is exciting. It also has on-board WiFi. This makes it doubly exciting!
One of my first thoughts was, can I use it as a SoftAP for some ESP8266 sensor nodes? As it turns out, you can, and it's not that difficult, as the BCM43438 chip is supported by the open-source brcmfmac driver!
Packages
The first step is to install the required packages: sudo apt-get install dnsmasq hostapd
I'll go into a little detail about the two:
• hostapd - This is the package that allows you to use the built in WiFi as an access point
• dnsmasq - This is a combined DHCP and DNS server that's very easy to configure
If you want something a little more 'heavyweight', you can use the isc-dhcp-server and bind9 packages for DHCP and DNS respectively, but for our purposes, dnsmasq works just fine.
Configure your interfaces
The first thing you'll need to do is to configure your wlan0 interface with a static IP.
If you're connected to the Pi via WiFi, connect via ethernet/serial/keyboard first.
In newer Raspian versions, interface configuration is handled by dhcpcd, so open up the dhcpcd configuration file with sudo nano /etc/dhcpcd.conf. We need to tell it that our wlan0 has a static IP address, so add the following lines to the bottom of the file:
interface wlan0
static ip_address=172.24.1.1/24
EDIT: We also need to prevent wpa_supplicant from running and interfering with setting up wlan0 in access point mode. To do this open up the interface configuration file with sudo nano /etc/network/interfaces and comment out the line containing wpa-conf in the wlan0 section, so that it looks like this:
allow-hotplug wlan0
iface wlan0 inet manual
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Restart dhcpcd with sudo service dhcpcd restart and it should assign your wlan0 interface with a static IP.
Configure hostapd
Next, we need to configure hostapd. Create a new configuration file with sudo nano /etc/hostapd/hostapd.conf with the following contents:
# This is the name of the WiFi interface we configured above
interface=wlan0

# Use the nl80211 driver with the brcmfmac driver
driver=nl80211

# This is the name of the network
ssid=Pi3-AP

# Use the 2.4GHz band
hw_mode=g

# Use channel 6
channel=6

# Enable 802.11n
ieee80211n=1

# Enable WMM
wmm_enabled=1

# Enable 40MHz channels with 20ns guard interval
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]

# Accept all MAC addresses
macaddr_acl=0

# Use WPA authentication
auth_algs=1

# Require clients to know the network name
ignore_broadcast_ssid=0

# Use WPA2
wpa=2

# Use a pre-shared key
wpa_key_mgmt=WPA-PSK

# The network passphrase
wpa_passphrase=raspberry

# Use AES, instead of TKIP
rsn_pairwise=CCMP
We can check if it's working at this stage by running sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf. If it's all gone well thus far, you should be able to see to the network Pi3-AP! If you try connecting to it, you will see some output from the Pi, but you won't receive and IP address until we set up dnsmasq in the next step. Use Ctrl+C to stop it.
We aren't quite done yet, because we also need to tell hostapd where to look for the config file when it starts up on boot. Open up the default configuration file with sudo nano /etc/default/hostapd and find the line #DAEMON_CONF="" and replace it with DAEMON_CONF="/etc/hostapd/hostapd.conf".
Configure dnsmasq
The shipped dnsmasq config file contains a wealth of information on how to use it, but the majority of it is largely redundant for our purposes. I'd advise moving it (rather than deleting it), and creating a new one with
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo nano /etc/dnsmasq.conf
Paste the following into the new file:
interface=wlan0 # Use interface wlan0
bind-interfaces # Bind to the interface to make sure we aren't sending things elsewhere
server=8.8.8.8 # Forward DNS requests to Google DNS
domain-needed # Don't forward short names
bogus-priv # Never forward addresses in the non-routed address spaces.
dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time
Set up IPv4 forwarding
One of the last things that we need to do before we send traffic anywhere is to enable packet forwarding.
To do this, open up the sysctl.conf file with sudo nano /etc/sysctl.conf, and remove the # from the beginning of the line containing net.ipv4.ip_forward=1. This will enable it on the next reboot, but because we are impatient, activate it immediately with :
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
We also need to share our Pi's internet connection to our devices connected over WiFi by the configuring a NAT between our wlan0 interface and our eth0 interface. We can do this using the following 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
However, we need these rules to be applied every time we reboot the Pi, so run sudo sh -c "iptables-save > /etc/iptables.ipv4.nat" to save the rules to the file /etc/iptables.ipv4.nat. Now we need to get dhcpcd to run this, so create a new file with sudo nano /lib/dhcpcd/dhcpcd-hooks/70-ipv4-nat with the contents:
iptables-restore < /etc/iptables.ipv4.nat
We're almost there!
Now we just need to start our services:
sudo service hostapd start
sudo service dnsmasq start
And that's it! You should now be able to connect to the internet through your Pi, via the on-board WiFi!
To double check we have got everything configured correctly, reboot with sudo reboot."

Può essere utile???

"Se in un primo momento l'idea non è assurda, allora non c'è nessuna speranza che si realizzi" A. Einstein
"Meno comodità si hanno, meno bisogni si hanno.Meno bisogni si hanno e più si è felici" Jules Verne
12-05-2016 15:30
Trova tutti i messaggi di questo utente Cita questo messaggio nella tua risposta
Rispondi 


Messaggi in questa discussione
RE: GUIDA PRIMA INSTALLAZIONE Raspberry ed OpenPlotter (Agg. 23/03) - Capitan Papino - 12-05-2016 15:30

Discussioni simili
Discussione: Autore Risposte: Letto: Ultimo messaggio
  Installazione KIT trasformazione WC elettrico Jonah11 6 411 25-09-2024 18:22
Ultimo messaggio: Jonah11
  Installazione Renogy dcdc 30 dual maurizio-74 8 1.597 19-09-2024 18:04
Ultimo messaggio: Lucignolo77
  Installazione inverter: qualche consiglio? itamabo 49 16.877 15-07-2024 22:14
Ultimo messaggio: Gabriele
  Installazione Garmin AIS 300 su rete Raymarine OK gr8wings 3 866 20-06-2024 11:05
Ultimo messaggio: AndreaB72
  openplotter cerco aiuto per configurare kip ginettosub 8 965 15-05-2024 23:37
Ultimo messaggio: ginettosub
  Installazione AIS kermit 21 5.512 30-03-2024 12:35
Ultimo messaggio: NICATA87
  Last news OpenPlotter! Resolution 0 448 15-01-2024 00:55
Ultimo messaggio: Resolution
  Installazione VHF di bordo Rockdamned 16 2.177 29-10-2023 19:31
Ultimo messaggio: bdc@live.it
  installazione AIS Matsutec HA-102 ghega 7 1.093 04-10-2023 21:10
Ultimo messaggio: ghega
  Guida installazione Axiom 7 GS 46.7 2003 TancrediCurrao 4 1.078 09-04-2023 11:49
Ultimo messaggio: kavokcinque

Vai al forum:


Utente(i) che stanno guardando questa discussione: 19 Ospite(i)