如何在 Debian 上设置接入点(WiFi 热点)

如何在 Debian 上设置接入点(WiFi 热点)

我正在尝试设置 AP,但卡住了。我正在使用Odroid U3WiFi 适配器是模块 3来自 Hardkernel。我也在使用 Debian Jessie。

不,我几乎可以让它工作了:Odroid 可以访问互联网并且其他设备(我的手机和平板电脑)可以看到网络,但是当我尝试连接到网络时,我收到消息:无法加入网络“myNetwork”。

我的hosts文件如下:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

auto lo br0
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual

# Bridge setup

# for dhcp address
#iface br0 inet dhcp
# bridge_ports eth0 wlan0

# for static ip
iface br0 inet static
bridge_ports eth0 wlan0
# adapt with your network settings
address 192.168.1.250
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 192.168.1.1
fns-search localdomain

我的 hostapd.conf 文件是:

    interface=wlan0
driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=RaspAP
hw_mode=g
wpa=2
channel=8
wpa_passphrase=raspiwlan
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
beacon_int=100
auth_algs=3
wmm_enabled=1

ifconfig 的结果为:

    br0       Link encap:Ethernet  HWaddr 1e:fb:50:05:6b:da
          inet addr:192.168.1.250  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::1cfb:50ff:fe05:6bda/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:803 errors:0 dropped:0 overruns:0 frame:0
          TX packets:466 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:90238 (88.1 KiB)  TX bytes:48926 (47.7 KiB)

eth0      Link encap:Ethernet  HWaddr 1e:fb:50:05:6b:da
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1838 errors:0 dropped:0 overruns:0 frame:0
          TX packets:466 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:557975 (544.8 KiB)  TX bytes:54146 (52.8 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:390 errors:0 dropped:0 overruns:0 frame:0
          TX packets:390 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:25662 (25.0 KiB)  TX bytes:25662 (25.0 KiB)

mon.wlan0 Link encap:UNSPEC  HWaddr 00-A8-2B-00-05-4D-00-00-00-00-00-00-00-00-00-00
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:21913 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:6729206 (6.4 MiB)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 00:a8:2b:00:05:4d
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:17 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2828 (2.7 KiB)  TX bytes:2490 (2.4 KiB)

经过一番研究,我在 SO 上找到了一个答案(不幸的是链接丢失了),其中表明问题可能与连接到 Odroid 的设备的动态 IP 地址有关,但我不确定情况是否如此。有什么建议吗?

非常感谢

答案1

以下是创建 WiFi AP 的脚本:

  • SetupWiFi.sh- 设置 WiFi 网络并与 wlan0 共享 eth0。更改“ssid”和“wpa_passphrase”以设置 WiFi SSID(AP 名称)和密码。
  • StartWifi.sh- 启动 WiFi。(SetupWiFi.sh已经启动,因此您可以第一次跳过它。)
  • StopWiFi.sh- 停止它。

设置WiFi.sh:

#!/bin/bash
apt-get install -y hostapd dnsmasq wireless-tools iw wvdial

sed -i 's#^DAEMON_CONF=.*#DAEMON_CONF=/etc/hostapd/hostapd.conf#' /etc/init.d/hostapd

cat <<EOF > /etc/dnsmasq.conf
log-facility=/var/log/dnsmasq.log
#address=/#/10.0.0.1
#address=/google.com/10.0.0.1
interface=wlan0
dhcp-range=10.0.0.10,10.0.0.250,12h
dhcp-option=3,10.0.0.1
dhcp-option=6,10.0.0.1
#no-resolv
log-queries
EOF

service dnsmasq start

ifconfig wlan0 up
ifconfig wlan0 10.0.0.1/24

iptables -t nat -F
iptables -F
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
echo '1' > /proc/sys/net/ipv4/ip_forward

cat <<EOF > /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
channel=1

ssid=WiFiAP
wpa=2
wpa_passphrase=YOUR_PASSWORD
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
# Change the broadcasted/multicasted keys after this many seconds.
wpa_group_rekey=600
# Change the master key after this many seconds. Master key is used as a basis
wpa_gmk_rekey=86400

EOF

service hostapd start

启动WiFi.sh:

#!/bin/bash
service hostapd start
service dnsmasq start

StopWiFi.sh:

#!/bin/bash
service hostapd stop
service dnsmasq stop

笔记:

  • 在 Debian 7 上测试,但应该可以在较新的版本上运行。
  • 确保你正在运行超级用户。(对于新手)使用以下命令使这些文件可执行chmod +x 'SetupWiFi.sh'

希望能帮助到你。

相关内容