静态IP和自动wifi连接的网络配置

静态IP和自动wifi连接的网络配置

我想将我的Raspberry Pi设置为静态IP设备,它通过以太网进行通信(通过像192.168.20.X这样的IP),同时它应该通过WLAN(192.168.1.1)连接到互联网。但是,当我允许“auto eth0”时,它不会配置 wlan0。我希望他们俩都能工作。我当前的配置如下:

source-directory /etc/network/interfaces.d
auto lo

iface lo inet loopback

auto eth0  
iface eth0 inet static
 address 192.168.20.40
 netmask 255.255.255.0
 network 192.168.20.1
 gateway 192.168.20.1


allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

我缺少什么?任何帮助,将不胜感激。提前致谢。

解决了:

source-directory /etc/network/interfaces.d
auto lo

iface lo inet loopback

auto eth0  
iface eth0 inet static
 address 192.168.20.45
 netmask 255.255.255.0
 network 192.168.20.1
 gateway 192.168.1.1    # Changing this worked
 dns-nameservers 8.8.8.8 8.8.4.4

allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

答案1

我有类似的配置:静态 ip oneth0和动态 ip on wlan0

/etc/network/interfaces这是我的文件的内容:

# 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 lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

我配置 dhcp 或静态地址的位置位于/etc/dhcpcd.conf

interface eth0
static ip_address=192.168.20.40
static routers=192.168.20.1
nogateway

interface wlan0
static routers=192.168.1.1
static domain_name_servers=8.8.8.8 8.8.4.4

(我根据您的配置调整了该文件)

您还必须配置 Wifi(SSID、密码等)/etc/wpa_supplicant/wpa_supplicant.conf(我想您已经这样做了)

笔记:我正在使用树莓派杰西。我认为在以前的版本中(喘息)网络配置是不同的

编辑:添加了DNS配置

答案2

解决了:

source-directory /etc/network/interfaces.d
auto lo

iface lo inet loopback

auto eth0  
iface eth0 inet static
 address 192.168.20.45
 netmask 255.255.255.0
 network 192.168.20.1
 gateway 192.168.1.1    # Changing this worked
 dns-nameservers 8.8.8.8 8.8.4.4

allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

相关内容