日常都是使用ssh来开发跟管理树莓派,偶尔用一下远程桌面,但是路由器的DHCP服务器经常会给树莓派分配不同的IP地址,每次登录路由器查看比较麻烦。本文介绍三种方法将树莓派的IP地址设置为固定IP。
实验环境
硬件:树莓派3b一台
操作系统:Raspbian with Desktop
方法一、使用路由器设置
使用浏览器登录路由器,在地址栏输入:192.168.1.1,然后回车,默认的账号密码都是admin。部分路由器可能不是这个地址,可以从路由器背面查看操作引导。


点击保存即可。MAC地址可以在树莓派终端下输入:
pi@raspberrypi:~ $ ifconfig -a

方法二、修改/etc/network/interfaces文件设置
终端下输入
pi@raspberrypi:~ $ sudo nano /etc/network/interfaces
原先网卡IP是从DHCP服务器获取的,找到下面这一句
iface eth0 inet dhcp
我们需要改为静态IP,将这一句替换为如下内容,如果找不到这一句就直接填写下面的内容到文件最后
iface eth0 inet static
#固定IP地址
address 192.168.1.201
#掩码,可以登录路由器查看
netmask 255.255.255.0
#网关,可以登录路由器查看
gateway 192.168.1.1
#DNS服务器
dns-nameservers 114.114.114.114
eth0是有线网卡,如果连接的是无线网络,把eth0改成wlan0
iface wlan0 inet static
address 192.168.1.202
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 114.114.114.114
方法三、进入桌面设置
右键点击菜单栏上面网络的图标


最后
重启树莓派。
关注微信公众号及时获取更新文章,欢迎大家跟我交流技术与想法:

网友评论