树莓派3b+更改静态IP

ubuntu系统修改静态IP的方法是在修改/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

稍微翻译一下:注意这个文件和dhcpcd一起使用,要更改静态IP的话要参照/etc/dhcpcd.conf 和 shell里输man dhcpcd.conf查看手册。

因此要改静态IP就要更改/etc/dhcpcd.conf文件。

在此文件后面添加

interface wlan0
static ip_address=192.168.8.88/24
static routers=192.168.8.1
static domain_name_servers=192.168.8.1

wlan0是无线配置,想设置有线配置可以改成eth0(网卡用ifconfig来查询)

ip_address是要配置的静态IP,后面要加上/24,代表子网掩码位数。表示32位的字码掩码前24位是1,即为(11111111,11111111,11111111,00000000),换算成十进制就是255.255.255.0

routers是路由地址

domain_name_servers是DNS,填路由地址就行了

最后在shell中输入命令

sudo reboot now

重启,登录路由器后台,看到已经IP已经改变

over

 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

如果想在烧录系统时就更改为静态IP

在把TF插入linux环境的电脑中,然后切换至挂载的磁盘/etc/dhcpcd.conf目录下

输入

sudo chmod 666 dhcpcd.conf

使文件可写,然后

gedit dhcpcd.conf

直接把静态IP信息复制到dhcpcd.conf文件,按Ctrl+S保存

原文地址:https://www.cnblogs.com/haoyufang/p/11774144.html