Raspberry Pi 作为 WLAN 热点和 LAN 上的静态 IP

问题描述

我有一个带有 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

只有当 eth0 不是静态时才会创建 WLAN,但是当 IP 是静态时,DHCP 无法启动并且 WLAN 不起作用。

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

亲切的问候, 沃尔夫冈

解决方法

这对我来说并不完全清楚,但是.. 我的 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 上。

,

感谢 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 或接口文件定义的,这有区别吗? dhcpcd.conf 看起来如何具有相同的行为?

亲切的问候, 沃尔夫冈