Template:HOSTAPD ACCESS POINT: Difference between revisions
From Variscite Wiki
(Created page with "<includeonly></includeonly>") |
|||
(12 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<includeonly></includeonly> | <includeonly> | ||
== Configuring WiFi access point with hostapd == | |||
hostapd is a versatile tool for setting up a WiFi access point and generally offers more options and flexibility compared to NetworkManager. For instance, hostapd enables the creation of a WiFi 6 access point, which is not currently possible with NetworkManager. | |||
While NetworkManager facilitates complete automation of WiFi, DHCP server, and NAT configuration, hostapd provides more granular control over these settings, making it a preferred choice for advanced configurations. | |||
dnsmasq is a suitable option for providing DHCP and DNS services alongside hostapd. It's a lightweight DNS forwarder and DHCP server that can be easily integrated with hostapd. | |||
=== Make sure interface (uap0) is not managed by NetworkManager === | |||
Before starting with hostapd, it's important that NetworkManager is not managing the access point interface (uap0). If NetworkManager is running, make sure uap0 is unmanaged: | |||
# /etc/NetworkManager/conf.d/99-iw61x-unmanaged-devices.conf | |||
[keyfile] | |||
unmanaged-devices=interface-name:uap0; | |||
=== Create /etc/hostapd.conf === | |||
The next step is to create /etc/hostapd.conf. The following table shows how to configure 802.11bgn, 802.11ac, and 802.11ax access points: | |||
{| class="wikitable" | |||
|- | |||
! Wi-Fi 2.4GHz (802.11bgn)<br>/etc/hostapd.conf | |||
! Wi-Fi 5 (802.11ac)<br>/etc/hostapd.conf | |||
! Wi-Fi 6 (802.11ax)<br>/etc/hostapd.conf | |||
|- | |||
| {{HOSTAPD_BGN}} | |||
| {{HOSTAPD_AC}} | |||
| {{HOSTAPD_AX}} | |||
|} | |||
Note: When copying the text above, your file may contain zero width spaces at the end of each line (appearing as `^^k` in nano or hex `e2 80 8b` in hexdump). This will cause hostapd to fail. You can fix it by running: | |||
# sed 's/\xe2\x80\x8b//g' /etc/hostapd.conf > /etc/hostapd_cleaned.conf && mv /etc/hostapd_cleaned.conf /etc/hostapd.conf | |||
=== Configure /etc/dnsmasq.conf === | |||
<pre> | |||
# /etc/dnsmasq.conf | |||
interface=uap0 # Use the interface uap0 for DHCP | |||
no-dhcp-interface=eth0 # Disable DHCP on eth0 | |||
no-dhcp-interface=wlan0 # Disable DHCP on wlan0 | |||
no-dhcp-interface=wfd0 # Disable DHCP on wfd0 | |||
# Configure ipv4 address range | |||
dhcp-range=192.168.10.10,192.168.10.100,12h # Set the DHCP range and lease time | |||
# Configure ipv6 address range | |||
dhcp-range=fd00:1234::10,fd00:1234::100,12h # Set the DHCPv6 range and lease time | |||
# Enable Router Advertisement (RA) to inform clients of the IPv6 prefix | |||
enable-ra | |||
</pre> | |||
Then, assign uap0 an ip and start hostapd and dnsmasq: | |||
# ip addr add 192.168.10.1/24 dev uap0 | |||
# ip -6 addr add fd00:1234::1/64 dev uap0 | |||
# systemctl restart hostapd | |||
# systemctl restart dnsmasq | |||
At this point, devices can connect and dhcp an ip address using the access point on uap0. | |||
=== Optionally configure NAT between uap0 and eth0: === | |||
<pre> | |||
# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | |||
# iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT | |||
# iptables -A FORWARD -i uap0 -o eth0 -j ACCEPT | |||
</pre> | |||
and allow ip forwarding by appending /etc/sysctl.conf: | |||
# /etc/sysctl.conf | |||
net.ipv4.ip_forward=1 | |||
net.ipv6.conf.all.forwarding=1 | |||
Now, devices connecting to the access point on uap0 will have network access through eth0. | |||
</includeonly> |