靜態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

相關內容