User Tools

Site Tools


guifi.net:hotspot

This is an old revision of the document!


Bullet M2

No se le puede poner openwrt, la dejamos como bridge y delegamos en una raspberry

Hotspot con wifi Raspberry

Fuente: https://pimylifeup.com/raspberry-pi-captive-portal/

Hotspot con el wifi de Raspberry haciendo de AP y conectada por cable a internet

Configuración básica raspberry

Imagen: 2020-02-13-raspbian-buster-lite.img

sudo dd if=2020-02-13-raspbian-buster-lite.img of=/dev/mmcblk0

Tarda 12 minutos con dell latitude E5470 y 5 minutos con dell latitude 5400:

3612672+0 records in
3612672+0 records out
1849688064 bytes (1.8 GB, 1.7 GiB) copied, 760.353 s, 2.4 MB/s

Modificamos la tarjeta para poder acceder sin monitor:

Ponemos IP fija cambiando el fichero /etc/dhcpcd.conf añadiendo al final:

interface eth0
static ip_address=192.168.1.13/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

Habilitamos ssh dejando un fichero en la partición boot que se llame ssh (da igual el contenido o si está vacio)

Ya podemos acceder por ssh

Login: pi
Password: raspberry

Si queremos cambiar el teclado a español:

sudo raspi-config
4 Localisation Options Set up language and regional settings to match your location
I3 Change Keyboard Layout Set the keyboard layout to match your keyboard

Keyboard model:
Generic 105-key PC (intl.)
Keyboard layout:
Other
Country of origin for the keyboard:
Spanish
Ahora ya nos aparece una lista de todos los teclados Spanish. Cogemos el primero por ejemplo.
Keyboard layout:
Spanish
Key to function as AltGr:
The default for the keyboard layout
Compose key:
No compose key

Actualizamos paquetes:

sudo apt-get update
sudo apt-get upgrade

Instalamos vim

sudo apt-get install -y vim

Configuramos vim, añadimos a los ficheros:

echo "set mouse-=a" > /home/pi/.vimrc
sudo su -c "echo 'set mouse-=a' > /root/.vimrc"

Configuración tunel entre wifi y cable

Si queremos poner ip fija a eth0:

sudo vim /etc/dhcpcd.conf

Y al final del fichero añadimos:

interface eth0
static ip_address=192.168.1.13/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8

Para configurar el wifi primero tenemos que poner el pais.
Si nos fijamos, al arrancar la raspberry sale el mensaje:

Wi-Fi is currently blocked by rfkill.
Use raspi-config to set the country before use.

Al hacer un iwconfig no aparece Tx-Power

wlan0     IEEE 802.11  ESSID:off/any  
          Mode:Managed  Access Point: Not-Associated   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:on

Habilitamos country en wifi

sudo raspi-config
4 Localisation Options Set up language and regional settings to match your location
I4 Change Wi-fi Country   Set the legal channels used in your country
ES Spain

Ahora al hacer iwconfig si vemos Tx-Power

iwconfig
wlan0     IEEE 802.11  ESSID:off/any  
          Mode:Managed  Access Point: Not-Associated   Tx-Power=31 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:on

Ahora configuramos el wifi de la raspberry como access point:

sudo apt-get install -y hostapd dnsmasq
sudo systemctl stop hostapd
sudo systemctl stop dnsmasq

Añadimos al final de la configuración de DHCP:

sudo vim /etc/dhcpcd.conf
interface wlan0
    static ip_address=192.168.220.1/24

Reiniciamos dhcp:

sudo systemctl restart dhcpcd
sudo vim /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211

hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=0
macaddr_acl=0
ignore_broadcast_ssid=0

auth_algs=1
wpa=0

# This is the name of the network
ssid=raspberry

Modificamos estos 2 ficheros:

sudo vim /etc/default/hostapd

Cambiamos esta línea:

#DAEMON_CONF="" 

Por:

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

Y este otro que en mi caso ya estaba cambiado:

sudo vim /etc/init.d/hostapd

Cambiamos esta línea:

DAEMON_CONF= 

Por esta:

DAEMON_CONF=/etc/hostapd/hostapd.conf

Ahora configuramos DHCP:

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo vim /etc/dnsmasq.conf
interface=wlan0       # Use interface wlan0  
server=1.1.1.1       # Use Cloudflare DNS  
dhcp-range=192.168.220.50,192.168.220.150,12h # IP range and lease time  

Ahora enrutamos el tráfico de wifi a cable, es decir, de wlan0 a eth0

sudo vim /etc/sysctl.conf

Descomentamos:

net.ipv4.ip_forward=1

Añadimos IPTABLES:

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

Lo grabamos:

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Para hacer persistente en los reinicios:

sudo vim /etc/rc.local

Añadimos encima de la línea exit 0:

iptables-restore < /etc/iptables.ipv4.nat

Grabamos los servicios:

sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
sudo service dnsmasq start

Si miramos wlan0 vemos que ahora está como Mode:Master

iwconfig
lan0     IEEE 802.11  Mode:Master  Tx-Power=31 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:on

Reiniciamos

sudo reboot

Ya nos podemos conectar al wifi de la raspberry y salir por internet

Configuración Hotspot

Instalamos paquetes necesarios para portal captivo:

sudo apt install -y git libmicrohttpd-dev

Clonamos el repo de nodogsplash

git clone https://github.com/nodogsplash/nodogsplash.git

Compilamos:

cd nodogsplash
make
sudo make install

Modificamos estos parámetros de la configuración:

sudo vim /etc/nodogsplash/nodogsplash.conf
GatewayInterface wlan0
GatewayAddress 192.168.220.1
MaxClients 250
AuthIdleTimeout 480

Arrancamos el software:

sudo nodogsplash

Nos dará este error:

libmicrohttpd is out of date, please upgrade to version 0.9.69 or higher

Eso es porque raspbian no está actualizada, podemos forzar a que el hotspot no valide versiones antiguas o compilar a mano la versión que toca:

Saltar versiones antiguas:

sudo vim /etc/nodogsplash/nodogsplash.conf
use_outdated_mhd 1

Compilar nueva versión:
Hay que compilar y despues desinstalar los antiguos:

Descargamos nueva versión y compilamos:

cd ~
wget ftp://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.70.tar.gz
tar zxvf libmicrohttpd-0.9.70.tar.gz
mv libmicrohttpd-0.9.70 libmicrohttpd
cd libmicrohttpd
sudo ./configure
sudo make
sudo make install

Desinstalamos la versión antigua:

sudo apt-get remove -y libmicrohttpd12 libmicrohttpd-dev

Para que arranque en el principio, modificamos el fichero

sudo vim /etc/rc.local

Y añadimos encima de exit 0 la línea:

nodogsplash

Configuración nodogsplash

Fichero web entrada:

/etc/nodogsplash/htdocs/splash.html
guifi.net/hotspot.1587336808.txt.gz · Last modified: 2020/04/19 22:53 by jose