<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Negromax</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Negromax"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Negromax"/>
	<updated>2026-05-03T05:53:17Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Wireless_AP_with_udhcpd_and_NAT&amp;diff=16864</id>
		<title>Wireless AP with udhcpd and NAT</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Wireless_AP_with_udhcpd_and_NAT&amp;diff=16864"/>
		<updated>2020-02-07T17:46:21Z</updated>

		<summary type="html">&lt;p&gt;Negromax: /* Dependencies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Networking]]&lt;br /&gt;
Setting up a wireless AP with udhcpd and NAT&lt;br /&gt;
&lt;br /&gt;
(baseed largley on the [http://elinux.org/RPI-Wireless-Hotspot raspberry pi wireless router howto])&lt;br /&gt;
&lt;br /&gt;
= Dependencies =&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add hostapd busybox-extras iptables}}&lt;br /&gt;
&lt;br /&gt;
hostapd provides the AP.&lt;br /&gt;
udhcpd is the dhcp server.&lt;br /&gt;
&lt;br /&gt;
If you want to connect clients to the internet, you need to provide some way&lt;br /&gt;
of redirecting traffic from the AP to the rest of the internet.&lt;br /&gt;
There are two main possibilities:&lt;br /&gt;
*setting up a bridge&lt;br /&gt;
*using NAT (network address translation).&lt;br /&gt;
&lt;br /&gt;
If you use a bridge and get your IP via DHCP, you may have a hard time&lt;br /&gt;
configuring it so that the bridge gets an ip without screwing up your&lt;br /&gt;
local internet connection.&lt;br /&gt;
This guide only covers NAT; see [[Bridge]] for more on the alternative.&lt;br /&gt;
&lt;br /&gt;
= Configure hostapd =&lt;br /&gt;
You need to write a configuration file; Alpine ships with a sample one in&lt;br /&gt;
/etc/hostapd/hostapd.conf, but it didn&#039;t work for me (possibly because I&lt;br /&gt;
used a pre wireless-N card, supported by ath5k?).&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a sample one based on something that did work for me &lt;br /&gt;
(I&#039;ve changed ssid &amp;amp; wpa_passphrase):&lt;br /&gt;
 ctrl_interface=/var/run/hostapd&lt;br /&gt;
 ctrl_interface_group=0&lt;br /&gt;
 interface=wlan0&lt;br /&gt;
 driver=nl80211&lt;br /&gt;
 logger_syslog=-1&lt;br /&gt;
 logger_syslog_level=2&lt;br /&gt;
 logger_stdout=-1&lt;br /&gt;
 logger_stdout_level=2&lt;br /&gt;
 ssid=alpine-test&lt;br /&gt;
 hw_mode=g&lt;br /&gt;
 channel=6&lt;br /&gt;
 max_num_sta=32&lt;br /&gt;
 rts_threshold=2347&lt;br /&gt;
 fragm_threshold=2346&lt;br /&gt;
 macaddr_acl=0&lt;br /&gt;
 auth_algs=3&lt;br /&gt;
 ignore_broadcast_ssid=0&lt;br /&gt;
 wpa=2&lt;br /&gt;
 wpa_passphrase=supertopsecret&lt;br /&gt;
 wpa_key_mgmt=WPA-PSK WPA-PSK-SHA256&lt;br /&gt;
 wpa_pairwise=TKIP CCMP&lt;br /&gt;
&lt;br /&gt;
Change &amp;quot;interface&amp;quot; to match your wireless interface.&lt;br /&gt;
Change &amp;quot;ssid&amp;quot; and &amp;quot;wpa_passphrase&amp;quot; to suit your desires.&lt;br /&gt;
Set &amp;quot;wpa&amp;quot; to 3 if you want plain wpa and wpa2. or 1 for plain WPA1 only.&lt;br /&gt;
&lt;br /&gt;
The example in the package uses wpa_psk_file (needed for WPS) instead of a&lt;br /&gt;
static passphrase; this does not enable WPS.&lt;br /&gt;
&lt;br /&gt;
You may want to change the channel to avoid collision with other local APs.&lt;br /&gt;
Unfortunately, the automatic channnel selection (channel=0) is *not*&lt;br /&gt;
currently enabled at compile time, so we can&#039;t use it; scan for channels&lt;br /&gt;
in use with {{Cmd|iwlist wlan0 scanning}} or equivalent before setup.&lt;br /&gt;
&lt;br /&gt;
max_num_sta is a limit to the number of clients connecting to your AP.&lt;br /&gt;
Set it higher than you think you could have, but not much higher.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t put this in /etc/hostapd/hostapd.conf, you will need to change&lt;br /&gt;
the CONFIGS line in /etc/conf.d/hostapd to point at it.&lt;br /&gt;
I prefer doing that, so that the default is available for reference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Configure udhcpd =&lt;br /&gt;
&lt;br /&gt;
Edit /etc/udhcpd.conf.&lt;br /&gt;
The default is very well-commented, but not perfectly ready to use.&lt;br /&gt;
Here&#039;s a skeleton, loosely based on mine:&lt;br /&gt;
 start		192.168.2.2&lt;br /&gt;
 end		192.168.2.254&lt;br /&gt;
 max_leases	64&lt;br /&gt;
 interface	wlan0&lt;br /&gt;
 static_lease	00:1b:de:ad:be:ef	192.168.2.100&lt;br /&gt;
 opt	dns	192.168.0.1 8.8.8.8&lt;br /&gt;
 opt	subnet	255.255.255.0&lt;br /&gt;
 opt	router	192.168.2.1&lt;br /&gt;
 opt	lease	864000&lt;br /&gt;
&lt;br /&gt;
Note the following:&lt;br /&gt;
*max_leases should be set to at least as many clients as you might have in&lt;br /&gt;
the lifetime of a lease; if you have any clients connecting via bridges,&lt;br /&gt;
note that the bridge itself gets a dhcp address.&lt;br /&gt;
*interface is the interface clients will be connecting to (wlan0 or your&lt;br /&gt;
wireless interface in our example)&lt;br /&gt;
*router should be the static IP address you give to your wireless interface.&lt;br /&gt;
*start and end should be within the same subnet as the IP you configure&lt;br /&gt;
wlan0 with, but the IP for wlan0 should be outside the range.&lt;br /&gt;
(For example: 192.168.2.1 and 192.168.2.255 are both suitable for the router&lt;br /&gt;
IP in this example.)&lt;br /&gt;
*set the dns option to point to any nameservers you want; you can repeat it,&lt;br /&gt;
but there&#039;s a maximum of 3 nameservers.&lt;br /&gt;
*static_lease takes two arguments: a MAC address designating a specific&lt;br /&gt;
network adaptor, and the IP address that should be assigned to it.&lt;br /&gt;
It can be repeated multiple times, to assign different IPs to different&lt;br /&gt;
users.&lt;br /&gt;
This comes in handy for printers, if you can trust those who connect to&lt;br /&gt;
the network to not do MAC spoofing.&lt;br /&gt;
&lt;br /&gt;
= Configure iptables =&lt;br /&gt;
&lt;br /&gt;
I used raw iptables, configuring it thus:&lt;br /&gt;
{{Cmd|iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE&lt;br /&gt;
iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT&lt;br /&gt;
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT&lt;br /&gt;
# this saves the state somewhere that the service can restore it from&lt;br /&gt;
service iptables save}}&lt;br /&gt;
&lt;br /&gt;
= Test =&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
/etc/init.d/hostapd start&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/udhcpd start&lt;br /&gt;
&lt;br /&gt;
sysctl net.ipv4.ip_forward=1&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
and try connecting from another computer.&lt;br /&gt;
&lt;br /&gt;
= Make changes permanent =&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-update add hostapd&lt;br /&gt;
rc-update add udhcpd&lt;br /&gt;
rc-update add sysctl}}&lt;br /&gt;
&lt;br /&gt;
== Configuring ifup ==&lt;br /&gt;
Now, the odd parts:&lt;br /&gt;
iptables tries to set net.ipv4.ip_forward to 1 when it&#039;s started, but in&lt;br /&gt;
my experience, this cannot be relied upon.&lt;br /&gt;
You do *not* want to enable the &amp;quot;iptables&amp;quot; service; it starts before&lt;br /&gt;
networking, and may result in your wireless interface not getting configured.&lt;br /&gt;
(Apparently, ifup thinks that wlan0 is up and skips it. This was not something I expected, but it&#039;s the only explanation I have for how things worked...)&lt;br /&gt;
&lt;br /&gt;
Rather, modify /etc/network/interfaces, commenting out any configuration for&lt;br /&gt;
your wireless interface. Then add this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
auto wlan0&lt;br /&gt;
iface wlan0 inet static&lt;br /&gt;
	address 192.168.2.1&lt;br /&gt;
	netmask 255.255.255.0&lt;br /&gt;
	up /etc/init.d/iptables start&lt;br /&gt;
	up sysctl net.ipv4.ip_forward=1&lt;br /&gt;
	down /etc/init.d/iptables stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(It would be possible to set everything up so that hostapd and udhcpd get&lt;br /&gt;
started and stopped from the wlan0 stanza; I didn&#039;t bother doing that.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Finishing touches =&lt;br /&gt;
&lt;br /&gt;
(See [[Setting_up_a_ssh-server]] for alternatives and more information)&lt;br /&gt;
Add dropbear SSH server, configure it to run on only the wireless interface:&lt;br /&gt;
{{Cmd|setup-sshd -c dropbear}}&lt;br /&gt;
edit /etc/conf.d/dropbear to add&lt;br /&gt;
&lt;br /&gt;
 DROPBEAR_OPTS=&amp;quot;-p 192.168.2.1:22&amp;quot;&lt;br /&gt;
&lt;br /&gt;
(assuming that the wireless interface has the IP 192.168.2.1 and you&lt;br /&gt;
want SSH on port 22).&lt;br /&gt;
This is optional, but if you&#039;re using a wireless router it helps to be able&lt;br /&gt;
to administer it, and listening on all addresses is rather risky.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Things this doesn&#039;t cover but it would be nice to =&lt;br /&gt;
*Some way to get more entropy (see [[Entropy_and_randomness]])&lt;br /&gt;
*DNS server, publishing device names ([[TinyDNS_Format]] looks most useful)&lt;br /&gt;
*use awall instead of raw iptables (and/or switch to nftables)&lt;br /&gt;
*[[Setup-acf]] to manage the router&lt;br /&gt;
This would require:&lt;br /&gt;
**acf-core, acf-alpine-conf, acf-apk-tools&lt;br /&gt;
**acf-iptables, or acf-awall + rewrite&lt;br /&gt;
**acf-ssh + switch to openssh, or new acf-dropbear&lt;br /&gt;
**acf-dhcp + switch to dhcp, or new acf-udhcpd&lt;br /&gt;
**new acf-hostapd (probably hardest part!)&lt;br /&gt;
**acf-tinydns after adding tinydns&lt;/div&gt;</summary>
		<author><name>Negromax</name></author>
	</entry>
</feed>