如何使用域名的方式使windows10电脑直接连接至树莓派

问题由来
众所周知,如果你的树莓派的系统是使用的不带桌面版本的,如Raspberry Pi OS Lite,或者Raspberry Pi OS Lite (Legacy)等。不能接显示屏意味着,你不知道你的树莓派的ip是多少,不知道你的树莓派连入网络的ip是多少,你就连接不到你的树莓派诶,喂!
众所周知,你的树莓派平常在办公室,ip是确定的,你用的嘎嘎好,嘎嘎六。当你拖着一天的疲惫回家,加班,打开背包,你的树莓派连入你家的网络的时候,你大喊一句:卧槽!怎么连不上树莓派了?因为此时ip改了!你的办公室的ip和家里的网络环境不一样的喂!
如何使用域名的方式连接树莓派
如果你想在不同的网络环境下,使用一个固定的域名就能连接至树莓派。那么请往下看:

软件准备

1. bonjour 软件-来自apple公司 在win10的cortana搜索栏中搜索"服务"->查找右边列表中是否有:"Bonjour 服务"或英文“Bonjour Service” 如果没有,请安装: https://developer.apple.com/bonjour/ 选择Bonjour Print Services for Windows 安装后,cortana搜索"服务"->查找右边列表中:"Bonjour 服务"或英文“Bonjour Service” 双击打开,确认启动类型为“自动” 2.xshell 软件 或 Putty 软件 或者 cmd xshell 下载地址为 https://www.xshell.com/zh/free-for-home-school/ Putty 下载地址为 https://the.earth.li/~sgtatham/putty/latest/w64/putty.exe

cmd

1.尝试ping方法获取ip,打开cmd,输入以下指令,可能会有效,但大多会提示Ping 请求找不到主机 raspberrypi.local。请检查该名称,然后重试。 ping -4 raspberrypi.local raspberrypi是默认的hostname,可以使用sudo raspi-config --> System Options --> Hostname 进行设置 2.尝试直接ssh至树莓派 ssh -4 pi@raspberrypi.local 其中pi是你的用户名(初试用户名为pi,按照你们自己的来改),raspberrypi是你的hostname,可以sudo raspi-config --> System Options --> Hostname 进行设置 然后,会提示你: The authenticity of host 'raspberrypi.local (192.168.137.xxx)' can't be established. ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. Are you sure you want to continue connecting (yes/no/[fingerprint])? 这里的(192.168.137.xxx)就是你的内网ip了 输入yes,并回车,然后会提示你输入密码,显示以下内容。 pi@raspberrypi.local's password: 初始密码一般为:raspberry,输入完毕后回车,如果你有修改,按照你的得来。

xshell

添加会话 --> 新建 --> 名称:随意 协议:SSH(默认) 主机:raspberrypi.localraspberrypi是默认的hostname) 端口号:22 互联网协议版本:选择IPv4

PuTTY

1. 左侧栏中选择Session(就是默认页) Host Name(or IP address)填入: raspberrypi.local 其中:(raspberrypi是默认的hostname) 2. 左侧栏中选择Connection 找到:Internet protocol version 选择 IPv4 3. 点击右下角的 Open 即可

如果报错的话,多试几次。。。。