WLAN Access Point APN

Erstellen des WLAN Access Point APN mit USB

Linux: Debian 12.7 (cat /etc/debian_version)

Liste den USB WLAN Stick

root@hpt:/home/tomas# lsusb
...
Bus 002 Device 003: ID 8087:0aa7 Intel Corp. Wireless-AC 3168 Bluetooth
...

Install Intel Firmware, da der USB Stick „Intel Corp. Wireless-AC 3168 Bluetooth“

apt install firmware-iwlwifi iw

Ermittle den Namen des WLAN Interfaces – in diesem Fall wlp2s0

root@hpt:/home/tomas# ll /sys/class/net/
lrwxrwxrwx 1 root root 0 Sep 24 08:12 enp1s0 -> ../../devices/pci0000:00/0000:00:02.2/0000:01:00.0/net/enp1s0
lrwxrwxrwx 1 root root 0 Sep 24 08:12 lo -> ../../devices/virtual/net/lo
lrwxrwxrwx 1 root root 0 Sep 24 08:12 wlp2s0 -> ../../devices/pci0000:00/0000:00:02.3/0000:02:00.0/net/wlp2s0

hostapn – AccessPoint

Install hostapd – betreibt den Accesspoint

apt install hostapd

Einstellungen in /etc/hostapd/hostapd.conf

### Wireless network name ###
interface=wlp2s0
driver=nl80211
ssid=tomastest
# a = IEEE 802.11a, b = IEEE 802.11b, g = IEEE 802.11g
hw_mode=g
channel=1
wpa=2
wpa_passphrase=test123456
## Key management algorithms ##
wpa_key_mgmt=WPA-PSK
#
## Set cipher suites (encryption algorithms) ##
## TKIP = Temporal Key Integrity Protocol
## CCMP = AES in Counter mode with CBC-MAC
wpa_pairwise=TKIP
rsn_pairwise=CCMP
#
## Shared Key Authentication ##
auth_algs=1
#
## Accept all MAC address ###
macaddr_acl=0

## Log-Einstellungen
# "-1" = alle Module loggen, "3" z.B. loggt nur WPA
logger_syslog=-1
# "2" = informative Meldungen, "1" = Debuggen, "0" = echt alles loggen
logger_syslog_level=2
# wie oben, nur Ausgabe auf Konsole, wenn Programm nicht im Hintergrund läuft
logger_stdout=-1
# wie oben
logger_stdout_level=1## Ländercode # Ländercode setzen country_code=DE # Ländercode aktivieren, "0" = aus (default) ieee80211d=1

Starte hostapn als root um Verbindungen zu testen:

root@hpt:/home/tomas# hostapd -d /etc/hostapd/hostapd.conf
...
wlp2s0: STA 62:61:aa:63:5f:50 IEEE 802.11: authentication OK (open system)
wlp2s0: STA 62:61:aa:63:5f:50 MLME: MLME-AUTHENTICATE.indication(62:61:aa:63:5f:50, OPEN_SYSTEM)
wlp2s0: STA 62:61:aa:63:5f:50 MLME: MLME-DELETEKEYS.request(62:61:aa:63:5f:50)
...
wlp2s0: STA 62:61:aa:63:5f:50 WPA: pairwise key handshake completed (RSN)
wlp2s0: EAPOL-4WAY-HS-COMPLETED 62:61:aa:63:5f:50

Die Verbindung zu einem APN wurde erfolgreich hergestellt. Der standard logging für hostapn wurde ist im /var/log/syslog.

Starte hostapn als system dienst: root@hpt:/home/tomas# systemctl enable --now hostapd.service

Network Configuration

Der WLAN Adapter wlp2s0 muss eine feste IP Adresse haben in IP Bereich  dass NICHT dem lokalen Netz zugeordnet ist. Dieser IP Bereich dient lediglich den APN. In diesem Fall 10.0.0.1

root@hpt:/home/tomas# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug enp1s0
iface enp1s0 inet dhcp

# WLAN mit fester Adresse für hostapd
auto wlp2s0
iface wlp2s0 inet static
address 10.0.0.1
netmask 255.255.255.0
broadcast 10.0.0.255

Enable IPv4 Forwadinf in /etc/sysctl.conf

root@hpt:/home/tomas# cat /etc/sysctl.conf |grep ip_forward
# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1

Definiere IP tables rules

iptables -A FORWARD -o enp1s0 -i wlp2s0 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -o enp1s0 -j MASQUERADE

Install persistence iptables rules apt install iptables-persistent um diese Änderungen persistent zu machen

root@hpt:/home/tomas# cat /etc/iptables/rules.v4
# Generated by iptables-save v1.8.9 (nf_tables) on Sun Sep 22 13:42:43 2024
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A FORWARD -s 192.168.0.0/24 -i wlp2s0 -o enp1s0 -m conntrack --ctstate NEW -j ACCEPT
-A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
COMMIT
# Completed on Sun Sep 22 13:42:43 2024
# Generated by iptables-save v1.8.9 (nf_tables) on Sun Sep 22 13:42:43 2024
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o enp1s0 -j MASQUERADE
COMMIT
# Completed on Sun Sep 22 13:42:43 2024

DNSMasq – DNS und DHCP Server
Installiere lokalen DNS und DHCP Server: apt install dnsmasq

Einstellungen in /etc/init.d/dnsmasq.conf

server=192.168.178.1 # Forward alle DNS Anfrage zum vorhandenem DNS Server
interface=wlp2s0
except-interface=lo,enp1s0
bind-interfaces # Um Probleme mit dem Port 53 von systemd umzugehen
dhcp-range=interface:wlp2s0,10.0.0.20,10.0.0.30,12h
# Nur für debugging
log-queries
log-dhcp

Starten den Dienst systemctl enable --now dnsmasq.service

Ausgaben in /var/log/syslog

2024-09-24T12:31:28.636273+02:00 hpt dnsmasq-dhcp[19201]: 3835516886 available DHCP range: 10.0.0.20 -- 10.0.0.30
2024-09-24T12:31:28.636520+02:00 hpt dnsmasq-dhcp[19201]: 3835516886 vendor class: android-dhcp-14
2024-09-24T12:31:28.636637+02:00 hpt dnsmasq-dhcp[19201]: 3835516886 client provides name: Handy-von-Tomas
2024-09-24T12:31:28.636752+02:00 hpt dnsmasq-dhcp[19201]: 3835516886 DHCPREQUEST(wlp2s0) 10.0.0.24 62:61:aa:63:5f:50
2024-09-24T12:31:28.636878+02:00 hpt dnsmasq-dhcp[19201]: 3835516886 tags: interface:wlp2s0, wlp2s0
2024-09-24T12:31:28.636995+02:00 hpt dnsmasq-dhcp[19201]: 3835516886 DHCPACK(wlp2s0) 10.0.0.24 62:61:aa:63:5f:50 Handy-von-Tomas
...
2024-09-24T12:31:28.744018+02:00 hpt dnsmasq[19201]: query[A] connectivitycheck.gstatic.com from 10.0.0.24
2024-09-24T12:31:28.744232+02:00 hpt dnsmasq[19201]: forwarded connectivitycheck.gstatic.com to 192.168.178.1
2024-09-24T12:31:28.759666+02:00 hpt dnsmasq[19201]: reply connectivitycheck.gstatic.com is 172.217.18.99

Schreibe einen Kommentar