Add a lead sentence |
Consistency: syntax highlighting for code, File: prefix |
||
| 第56行: | 第56行: | ||
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" | sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" | ||
* iptables | * iptables | ||
< | <syntaxhighlight lang="bash"> | ||
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | ||
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT | sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT | ||
| 第63行: | 第63行: | ||
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat" | sudo sh -c "iptables-save > /etc/iptables.ipv4.nat" | ||
up iptables-restore < /etc/iptables.ipv4.nat | up iptables-restore < /etc/iptables.ipv4.nat | ||
</ | </syntaxhighlight> | ||
=== Service enable === | === Service enable === | ||
| 第72行: | 第72行: | ||
</pre> | </pre> | ||
* make symbolic link to rcS | * make symbolic link to rcS | ||
< | <syntaxhighlight lang="bash"> | ||
cd /etc/init.d/rc5.d | cd /etc/init.d/rc5.d | ||
# put udhcpd to the last | # put udhcpd to the last | ||
ln -s ../init.d/udhcpd S05udhcpd | ln -s ../init.d/udhcpd S05udhcpd | ||
ln -s ../init.d/hostapd S01hostapd | ln -s ../init.d/hostapd S01hostapd | ||
</ | </syntaxhighlight> | ||
* service | * service | ||
< | <syntaxhighlight lang="bash"> | ||
sudo systemctl enable hostapd.service | sudo systemctl enable hostapd.service | ||
sudo systemctl enable udhcpd.service | sudo systemctl enable udhcpd.service | ||
</ | </syntaxhighlight> | ||
2026年8月23日 (日) 18:01的最新修訂
Turning a Raspberry Pi into a Wi-Fi access point with hostapd and udhcpd, including the NAT configuration for sharing its uplink.
USB wifi dongle
ID 148f:3572 Ralink Technology, Corp. RT3572 Wireless Adapter
Software
sudo apt-get install hostapd udhcpd
dhcp server
- Edit the file /etc/udhcpd.conf and configure it like this:
start 192.168.42.2 # This is the range of IPs that the hostspot will give to client devices. end 192.168.42.20 interface wlan0 # The device uDHCP listens on. remaining yes opt dns 8.8.8.8 4.2.2.2 # The DNS servers client devices will use. opt subnet 255.255.255.0 opt router 192.168.42.1 # The Pi's IP address on wlan0 which we will set up shortly. opt lease 864000 # 10 day DHCP lease time in seconds
- Edit the file /etc/default/udhcpd and change the line:
DHCPD_ENABLED="no" to #DHCPD_ENABLED="no"
Hostapd
- edit the file /etc/hostapd/hostapd.conf
interface=wlan0 driver=nl80211 ssid=My_AP hw_mode=g channel=6 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=My_Passphrase wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
- Edit the file /etc/default/hostapd
#DAEMON_CONF="" to: DAEMON_CONF="/etc/hostapd/hostapd.conf"
Configure NAT (Network Address Translation)
- fordwarding
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
- iptables
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
up iptables-restore < /etc/iptables.ipv4.natService enable
- makae sure your runlevel
$runlevel N 5
- make symbolic link to rcS
cd /etc/init.d/rc5.d
# put udhcpd to the last
ln -s ../init.d/udhcpd S05udhcpd
ln -s ../init.d/hostapd S01hostapd- service
sudo systemctl enable hostapd.service
sudo systemctl enable udhcpd.service