【问题标题】:Raspberry Pi as WLAN hotspot and static IP on LANRaspberry Pi 作为 WLAN 热点和 LAN 上的静态 IP
【发布时间】:2021-03-01 10:25:19
【问题描述】:

我有一个带有 Raspberry Pi OS lite 的 Raspberry Pi 3B,我想将 Pi 用作 WLAN 热点和服务器,并在 eth0 上使用静态 IP (169.254.1.100)。

因此,我安装了 dnsmasq 和 hostapd 并编辑了以下文件:

我编辑了 /etc/dnsmasq.conf:

# DHCP-Server aktiv für WLAN-Interface
interface=wlan0

# DHCP-Server nicht aktiv für bestehendes Netzwerk
no-dhcp-interface=eth0

# IPv4-Adressbereich und Lease-Time
dhcp-range=192.168.1.100,192.168.1.200,255.255.255.0,24h

# DNS
dhcp-option=option:dns-server,192.168.1.1

我添加到/etc/dhcpcd.conf

interface wlan0
static ip_address=192.168.1.1/24

我编辑了 /etc/hostapd/hostapd.conf:

interface=wlan0

ssid=PI_WLAN
channel=1
hw_mode=g
ieee80211n=1
ieee80211d=1
country_code=AT
wmm_enabled=1

auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
wpa_passphrase=somePassword

我正在启动 WLAN

> sudo hostapd -dd /etc/hostapd/hostapd.conf

WLAN 仅在 eth0 不是静态的情况下创建,但当 IP 为静态时 DHCP 无法启动且 WLAN 不工作。

即使为 eth0 禁用了 DHCP,我如何才能为 WLAN0 启用 DHCP?

亲切的问候, 沃尔夫冈

【问题讨论】:

    标签: raspberry-pi wifi static-ip-address


    【解决方案1】:

    这对我来说并不完全清楚,但是.. 我的 pi 有一个 wlan 热点和以太网接口上的静态 IP 地址。那是你要的吗 ? 在这种情况下,我只需编辑/etc/dhcpcd.conf 添加:

    interface eth0
    static ip_address=192.168.0.4/24    
    static routers=192.168.0.254
    static domain_name_servers=192.168.0.254 8.8.8.8
    
    interface wlan0
    static ip_address=192.168.4.1/24
    nohook wpa_supplicant
    

    然后我安装了 hostapd,这是我的 hostapd.conf

    country_code=IT
    interface=wlan0
    ssid=myssd
    hw_mode=g
    channel=7
    macaddr_acl=0
    auth_algs=1
    ignore_broadcast_ssid=0
    wpa=2
    wpa_passphrase=password
    wpa_key_mgmt=WPA-PSK
    wpa_pairwise=TKIP
    rsn_pairwise=CCMP
    

    我的 dnsmasq.conf 是这样的(但老实说,我不记得曾经碰过它,也许它没有必要或自动完成..)

    interface=wlan0 # Listening interface
    dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
                    # Pool of IP addresses served via DHCP
    domain=wlan     # Local wireless DNS domain
    address=/gw.wlan/192.168.4.1
                    # Alias for this router
    

    我的 wlan 热点定义了 ssid,它为我分配了一个动态 IP 地址,而树莓派位于具有静态 IP 的不同 LAN 上。

    【讨论】:

      【解决方案2】:

      感谢 rok 的回答,但即使我使用文件中的预定义值,我也无法使用 dhcpcd.conf 配置静态 IP ? 之前我用 /etc/network/interfaces 文件定义了静态 IP:

      # interfaces(5) file used by ifup(8) and ifdown(8)
      
      # Please note that this file is written to be used with dhcpcd
      # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
      
      # Include files from /etc/network/interfaces.d:
      source-directory /etc/network/interfaces.d
      
      auto eth0
      iface eth0 inet static
      address 169.254.1.100
      netmask 255.255.255.0
      gateway 169.254.1.1
      

      静态IP是用dhcpcd.conf还是interfaces文件定义的有区别吗? dhcpcd.conf 看起来如何具有相同的行为?

      亲切的问候, 沃尔夫冈

      【讨论】:

      • 抱歉,您应该对我的回答发表评论,否则我看不到您的标签。无论如何,请使用我的建议,这是众所周知的工作。另一件事是您使用的类是特定的 IP 类,请阅读 here.. 尝试使用常见的 192.168...
      猜你喜欢
      • 2015-10-14
      • 2019-07-04
      • 1970-01-01
      • 2013-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多