Configurar una PC como access point con hostapd
								
								Ir a la navegación
				Ir a la búsqueda
				
					
								
							
		Cómo convertir en un access point tu laptop, PC, cubietruck, Raspberry Pi, etc.
Sumario
Requisitos
- Wireless interface card (WIC)
- Modo AP (Master, Infrastructure)
 - Driver nativo en Linux, no NDISwrapper.
 - Utilice el driver mac80211
 
 - hostapd 0.6.8+
 - Servidor DHCP (isc-dhcp-server, udhcpd, dnsmasq)
 
Opcionales para probar:
- iw (paquete wireless-tools)
 - wpa_supplicant
 
Soporta el modo AP una WIC? Usa el siguiente comando:
iw list
Checa que la salida incluya el rengón señalado:
  Supported interface modes:
     * IBSS
     * managed
     * AP                  <---
     * AP/VLAN
     * WDS
     * monitor
     * mesh point
Utiliza el driver mac80211? Usa este comando:
lsmod | grep 80211
mac80211 415761 1 b43 cfg80211 356930 2 b43,mac80211 rfkill 18387 5 cfg80211,hp_wmi,bluetooth
Instalar software
Debian/Ubuntu:
apt-get install hostapd isc-dhcp-server wireless-tools
Fedora:
yum install hostapd wireless-tools
Configurar la WIC
Si NetworkManager está en uso:
killall NetworkManager
Asignar una dirección fija:
ifconfig wlan0 192.169.42.1 netmask 255.255.255.0
Configurar hostapd
- /etc/default/hostapd
 
DAEMON_CONF="/etc/hostapd/hostapd.conf"
- /etc/hostapd/hostapd.conf
 
interface=wlan0 driver=nl80211 ssid=mi_red auth_algs=1 wpa=2 wpa_passphrase=secreto1 wpa_key_mgmt=WPA-PSK wpa_pairwise=CCMP TKIP rsn_pairwise=CCMP
Configurar isc-dhcp-server
- /etc/dhcp/dhcpd.conf
 
   option domain-name-servers 8.8.8.8;
   subnet 192.168.42.0 netmask 255.255.255.224 {
   range 192.168.42.02 192.168.42.20;
   option routers 192.168.42.1;
   }
Compartir internet
echo 1 > /proc/sys/net/ipv4/ip_forward iptables -F iptables -t nat -A POSTROUTING -o eth+ -j MASQUERADE iptables -A FORWARD -o eth+ -j ACCEPT
Para no permitir acceso a la LAN, incluyendo el access point, agregar estos comandos:
iptables -A INPUT -i wlan0 -d 192.168.42.1 -j LOG --log-prefix="firewall ap: " iptables -A INPUT -i wlan0 -d 192.168.42.1 -j DROP iptables -A FORWARD -i wlan0 -d 192.168.1.0/24 -j LOG --log-prefix="firewall lan: " iptables -A FORWARD -i wlan0 -d 192.168.1.0/24 -j DROP
Referencia: Tablas y cadenas en iptables en Chapter 6. Traversing of tables and chains en Iptables Tutorial 1.2.2 por Oskar Andreasson
Probar
Servidor
Ejecutar hostapd en la consola:
hostapd -d /etc/hostapd.conf
wlan0: interface state UNINITIALIZED->ENABLED wlan0: AP-ENABLED
Cliente
Generar hash de contraseña:
$ wpa_passphrase mi_red secreto1 > wpa_supplicant.conf
- wpa_supplicant.conf
 
   network={
           ssid="mi_red"
           #psk="secreto1"
           psk=2667f3d0e64a2d6888983f41327a9a05161724e24857776473427bde319cf8ed
   }
Conectar:
wpa_supplicant -i wlan0 -D wext -c wpa_supplicant.conf -d
Arrancar en cada inicio
Debian/Ubuntu:
sudo update-rc.d hostapd enable sudo update-rc.d isc-dhcp-server enable
- /etc/sysctl.conf
 
net.ipv4.ip_forward=1
- /etc/iptables.ipv4.nat
 
iptables-save > /etc/iptables.ipv4.nat
- /etc/network/interfaces
 
iface wlan0 inet static address 192.168.42.1 netmask 255.255.255.0 allow-hotplug eth0 iface eth0 inet dhcp up iptables-restore < /etc/iptables.ipv4.nat
Tips
- 80211b es el modo por omisión, 11Mb/s.
 - Para usar el modo 802.11g, 54Mb/s, incluir en hostapd.conf:
 
hw_mode=g
- Para usar el modo 802.11n, 72Mb/s, agregar en hostapd.conf:
 
wme_enabled=1 ieee80211n=1 ht_capab=[HT40+][SHORT-GI-40][DSSS_CCK-40]
Recursos
- Hostapd driver for RTL8188{C|CU|CUS} wifi chips, por Chhatoi Pritam Baral.