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

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

问题描述:

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

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 

解决:

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 

配置“为wlan0”使用静态IP

它会正常工作

+1

你好,感谢你的回答,你能帮我解释一下如何编辑这个文件吗?我加了自动为wlan0 IFACE为wlan0 INET静态 地址192.168.1.126 子网掩码255.255.255.0 网络192.168.1.1 网关192.168.1.1,但它没有工作 – mozcelikors

+0

请点击此链接 –

+1

https://thepihut.com/blogs/raspberry -pi-tutorials/16683276-how-to-setup-a-static-ip-address-on-your-raspberry-pi –