首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Raspberry Pi作为WLAN热点和LAN上的静态IP

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

Stack Overflow用户
提问于 2021-03-01 18:25:20
回答 2查看 591关注 1票数 0

我有一个树莓派3B与树莓派操作系统精简版,我想使用的Pi作为无线局域网热点和服务器与eth0上的静态IP (169.254.1.100)。

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

我编辑了/etc/dnsmasq.conf:

代码语言:javascript
复制
# 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

代码语言:javascript
复制
interface wlan0
static ip_address=192.168.1.1/24

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

代码语言:javascript
复制
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

代码语言:javascript
复制
> sudo hostapd -dd /etc/hostapd/hostapd.conf

只有当eth0不是静态的时,才创建无线局域网,但是当IP是静态的时,DHCP无法启动,并且无线局域网不工作。

即使为WLAN0禁用了动态主机配置协议,如何为eth0启用动态主机配置?

致以亲切的问候,沃尔夫冈

EN

回答 2

Stack Overflow用户

发布于 2021-03-03 16:53:36

我不是很清楚,但是..我的pi有一个wlan热点和一个以太网接口上的静态ip地址。这是你想要的吗?在本例中,我只需编辑/etc/dhcpcd.conf,添加:

代码语言:javascript
复制
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

代码语言:javascript
复制
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是这样的(但老实说,我不记得碰过它,也许这不是必须的,也可能是自动完成的……)

代码语言:javascript
复制
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

我有一个定义了ssid的wlan热点,它为我分配了一个动态IP地址,而raspberry则位于另一个具有静态ip的LAN上。

票数 0
EN

Stack Overflow用户

发布于 2021-03-05 15:07:59

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

代码语言:javascript
复制
# 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看起来是怎样拥有同样的行为的呢?

致以亲切的问候,沃尔夫冈

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66420346

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档