树莓派如何设置静态IP

参考链接:https://blog.csdn.net/m15511023218/article/details/87920263

参考的主要代码:

auto eth0
iface eth0 inet static
address 192.168.3.90
gateway 192.168.3.1
netmask 255.255.255.0

一直看网上说要在/etc/dhcpcd.conf里边改,说在/etc/network/interfaces里边改不行,所以一直尝试在/etc/dhcpcd.conf里边改,但是最终都是失败的,最后尝试了在/etc/network/interfaces里边改对了。

修改之后成功的内容为:

将/etc/network/interfaces里边内容修改如下:

source-directory /etc/network/interfaces.d

auto lo

iface lo inet loopback

auto etho inet dhcp

auto wlan0

allow-hotplug wlan0

iface wlan0 inet static

  address 192.168.50.111  #要制定的静态IP

  gateway 192.168.50.1  #网关

  netmask 255.255.255.0  #子网掩码

  wpa-ssid "hahah" #需要连接的wifi账号

  wpa-psk "1234567"   #需要连接的wifi密码

修改之后没有成功的内容是:

在/etc/dhcpcd.conf文件末尾输入:

interface eth0

static ip_address=192.168.0.10/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

interface wlan0

static ip_address=192.168.0.200/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

其中,eth0是有线的配置,wlan0是无线配置
ip_address就是静态IP,后面要接/24
routers是网关
static domain_name_servers是DNS

猜你喜欢

转载自www.cnblogs.com/ruigelwang/p/13193296.html