hostapd 和 dhcpcd 引导顺序

hostapd 和 dhcpcd 引导顺序

我使用 Raspberry Pi 作为 WiFi 接入点。

当我手动启动时,hostapddhcpcd就像一个魅力。但是当我重新启动主机时,dhcpcd首先启动并且无法理解应该wlan0用作客户端。之后,hostapd 无法访问,wlan0因为dhcpcd已经在使用它。

有没有办法影响这些服务的顺序?

答案1

我也有这个问题。我创建了一个小脚本来处理此订单,并自动执行您手动执行的所有配置。

您只需安装dnsmasqhostapd。不要启用或禁用任何服务。它将得到照顾。

eth-to-wifi-route.sh

#!/bin/bash

# Share Eth with WiFi Hotspot
#
# This script is created to work with Raspbian Stretch
# but it can be used with most of the distributions
# by making few changes. 
#
# Make sure you have already installed `dnsmasq` and `hostapd`
# Please modify the variables according to your need
# Don't forget to change the name of network interface
# Check them with `ifconfig`

ip_address="192.168.2.1"
netmask="255.255.255.0"
dhcp_range_start="192.168.2.2"
dhcp_range_end="192.168.2.100"
dhcp_time="12h"
eth="eth0"
wlan="wlan0"
ssid="Arpit-Raspberry"
psk="arpit1997"

sudo killall wpa_supplicant &> /dev/null
sudo rfkill unblock wlan &> /dev/null
sleep 2

sudo iptables -F
sudo iptables -t nat -F
sudo iptables -t nat -A POSTROUTING -o $eth -j MASQUERADE  
sudo iptables -A FORWARD -i $eth -o $wlan -m state --state RELATED,ESTABLISHED -j ACCEPT  
sudo iptables -A FORWARD -i $wlan -o $eth -j ACCEPT 

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

sudo ifconfig $wlan $ip_address netmask $netmask

sudo ip route del 0/0 dev $wlan &> /dev/null
a=`route | awk "/${eth}/"'{print $5+1;exit}'`
sudo route add -net default gw $ip_address netmask 0.0.0.0 dev $wlan metric $a

echo -e "interface=$wlan \n\
bind-interfaces \n\
server=8.8.8.8 \n\
domain-needed \n\
bogus-priv \n\
dhcp-range=$dhcp_range_start,$dhcp_range_end,$dhcp_time" > /etc/dnsmasq.conf

sudo systemctl restart dnsmasq

echo -e "interface=$wlan\n\
driver=nl80211\n\
ssid=$ssid\n\
hw_mode=g\n\
ieee80211n=1\n\
wmm_enabled=1\n\
macaddr_acl=0\n\
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]\n\
channel=6\n\
auth_algs=1\n\
ignore_broadcast_ssid=0\n\
wpa=2\n\
wpa_key_mgmt=WPA-PSK\n\
wpa_passphrase=$psk\n\
rsn_pairwise=CCMP" > /etc/hostapd/hostapd.conf

sudo systemctl stop hostapd
sudo hostapd /etc/hostapd/hostapd.conf &

下载此文件并将其放置在/home/pi/

打开/home/pi/.config/lxsession/LXDE-pi/autostart文件

nano /home/pi/.config/lxsession/LXDE-pi/autostart

添加最后一行:

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@point-rpi
sudo bash /home/pi/eth-to-wifi-route.sh

确保提供文件的完整路径。你就完成了。现在重新启动以查看更改

sudo reboot

这是托管在 Github 上的这里

相关内容