自动更新 hosts文件解决ubuntu上deskflow不能识别windows主机名问题

  1. 获取 windows主机名, 更新hosts 文件
#!/bin/bash

# 获取 Windows 主机的 IP 地址
WINDOWS_IP=$(nmblookup anxin755 | grep -oP '(\d+\.){3}\d+' | head -n 1)

# 更新 /etc/hosts
sudo sed -i "/anxin755/d" /etc/hosts  # 删除旧记录
echo "$WINDOWS_IP   anxin755" | sudo tee -a /etc/hosts > /dev/null  # 添加新记录
  1. 开机启动时更新一次: cp update_hosts.sh /etc/

  2. 每小时自动更新一次: cp update_hosts.sh /etc/cron.hourly

posted @ 2025-03-13 16:51  AI健康  阅读(85)  评论(0)    收藏  举报