quick linux wifihotspot

To launch a basic wifi hotspot you need: iwconfig, iptables, dnsmasq, hostapd on your Linux box. Install it. Enable it (systemct enable).

To search what package a file belongs to, help youself an use:

apt-filesearch package

or

pacman -Fys package

Check if your system is compatibile with hostap, use iwconfig to list interfaces.


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

eth0      no wireless extensions.

lo        no wireless extensions.

Edit or create desired files.

For dnsmasq use your internal adress space.

#
# /etc/dnsmasq/dnsmasq.conf
#
dhcp-range=192.168.1.64,192.168.1.128,12h

For Debian edit /etc/default/dnsmasq and add following:

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

For hostpad, change parameters for interface (interface), name of your wifi network (ssid), wifimode (hw_mode), channel (channel), password (wpa_passphrase), and use or not isolation (ap_isolate), hide your wifi or not (ignore_broadcast_ssid).

#
# /etc/hostapd/hostapd.conf
#
interface=wlan0
driver=nl80211
hw_mode=g
#ieee80211n=0
#ieee80211n=1
channel=4
ssid=private

auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
wpa_passphrase=12345678


#ap_isolate=1
ignore_broadcast_ssid=0

Create script to run hotsopt and internet sharing, define yours external and internal interfaces (EXTIF, INTIF) and make it executable.

#
# masq.sh
#
#!/bin/sh
EXTIF=eth0
INTIF=wlan0
echo killing processes if something is using wifi interface
airmon-ng check kill
ip a a dev $INTIF 192.168.1.254/24
ip l set dev $INTIF up
echo '(re)starting dnsmasq'
systemctl restart dnsmasq
echo '(re)starting hostpad'
systemctl restart hostapd
echo flushing...
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
echo setting ip_forward...
echo 1 > /proc/sys/net/ipv4/ip_forward
#echo loading modules...
#modprobe ipt_MASQUERADE
echo configuring NAT...
iptables -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE
iptables -A FORWARD -i $EXTIF -o $INTIF -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT

Troubleshooting:

hostapd -d /etc/hostapd/hostapd.conf

Of course you can do everything your own way. It is just an outline of how to run basic Acces Point.
I’m using it on my RaspberryPi.