平时使用 Ubuntu 做远程开发时,如果设备连接的是手机热点或者 WiFi,经常会遇到:
-
Ubuntu IP 经常变化
-
每次都要重新查 IP
-
VSCode Remote SSH 很麻烦
这里使用:
avahi + mDNS
实现:
eaibot.local
固定连接。
这样:
-
不需要查 IP
-
不需要 Tailscale
-
不影响 GitHub Copilot
-
VSCode Remote SSH 稳定
-
NoMachine 可正常使用
一、Ubuntu 安装 avahi
Ubuntu:
sudo apt update
sudo apt install avahi-daemon -y
二、设置 Ubuntu 主机名
例如:
sudo hostnamectl set-hostname eaibot
查看:
hostname
输出:
eaibot
即可。
三、启动 avahi
Ubuntu:
sudo systemctl enable avahi-daemon
sudo systemctl start avahi-daemon
四、检查 avahi 状态
systemctl status avahi-daemon
看到:
active (running)
即可。
五、Windows 测试
Windows CMD / PowerShell:
ping eaibot.local
如果看到:
正在 Ping eaibot.local [192.168.x.x]
说明:
mDNS 配置成功。
六、SSH 测试
Windows:
ssh your_username@eaibot.local
七、VSCode Remote SSH 配置
Windows:
~/.ssh/config
添加:
Host eaibot
HostName eaibot.local
User your_username
然后:
Remote-SSH: Connect to Host
→ eaibot
即可远程开发。
八、NoMachine 使用
NoMachine Host:
eaibot.local
即可。
适合:
-
ROS
-
Gazebo
-
RViz
-
MATLAB
-
Linux GUI
九、如果 SSH 无法连接
Ubuntu 安装 SSH:
sudo apt install openssh-server -y
启动:
sudo systemctl enable ssh
sudo systemctl start ssh
查看状态:
systemctl status ssh
十、最终效果
最终开发架构:
Windows
├── VSCode
├── GitHub Copilot
└── NoMachine
↓
eaibot.local
↓
Ubuntu
特点:
-
不需要查 IP
-
手机热点也能稳定连接
-
不需要 Tailscale
-
不影响 Copilot
-
VSCode Remote SSH 稳定