无法通过网络连接到 Azure Linux VM
注意
本文中引用的 CentOS 是 Linux 发行版, (EOL) 将达到生命周期结束。 相应地考虑使用和计划。 有关详细信息,请参阅 CentOS 生命周期终止指南。
本文修复了网络错误阻止你连接到 Azure Linux 虚拟机的问题。
原始产品版本: 运行 Linux 的虚拟机
原始 KB 编号: 4010059
症状
Azure Linux 虚拟机 (VM) 上的主接口为 eth0。 如果未配置 eth0,则即使其他工具指示 VM 已启动,也无法通过网络连接访问 VM。
发生此问题时,具有正确权限的安全外壳 (SSH) 连接可能会开始连接到 VM。 但是,由于网络问题,它最终无法访问 VM。
网络错误通常记录在串行控制台日志中。 具体而言,你可能会看到以下错误。
串行控制台日志中的错误
CentOS Linux 分发错误
错误 1
Bringing up interface eth0:
Device eth0 does not seem to be present, delaying initialization.
[FAILED]
错误 2
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Device eth0 has different MAC address than expected, ignoring.
[FAILED]
错误 3
YYYY/MM/DD HH:MM:SS Discovered Windows Azure endpoint: ###.##.###.##
/usr/sbin/waagent:2275: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
Error('socket IOError ' + e.message + ' args: ' + repr(e.args))
YYYY/MM/DD HH:MM:SS ERROR:socket IOError args: (113, 'No route to host')
YYYY/MM/DD HH:MM:SS ERROR:socket IOError args: (113, 'No route to host')
Failed services in runlevel 3:network
错误 4
login: YYYY/MM/DD HH:MM:SS ERROR:timed out
YYYY/MM/DD HH:MM:SS ERROR:Traceback (most recent call last):
YYYY/MM/DD HH:MM:SS ERROR: File "/usr/sbin/waagent", line 3395, in DoDhcpWork
YYYY/MM/DD HH:MM:SS ERROR: receiveBuffer = sock.recv(1024)
YYYY/MM/DD HH:MM:SS ERROR:timeout: timed out
YYYY/MM/DD HH:MM:SS ERROR:
YYYY/MM/DD HH:MM:SS DoDhcpWork: Setting socket.timeout=10, entering recv
YYYY/MM/DD HH:MM:SS ERROR:timed out
YYYY/MM/DD HH:MM:SS ERROR:Traceback (most recent call last):
YYYY/MM/DD HH:MM:SS ERROR: File "/usr/sbin/waagent", line 3395, in DoDhcpWork
YYYY/MM/DD HH:MM:SS ERROR: receiveBuffer = sock.recv(1024)
YYYY/MM/DD HH:MM:SS ERROR:timeout: timed out
Customer changed the IP from DHCP to FIXED
SUSE Linux 分发错误
Setting up (localfs) network interfaces:
lo
lo IP address: 127.0.0.1/8
IP address: 127.0.0.2/8
done eth4
No configuration found for eth4
unused Waiting for mandatory devices: eth0
29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
eth0 No interface found
Ubuntu
错误 1
cloud-init-nonet waiting 120 seconds for a network device.
cloud-init-nonet gave up waiting for a network device.
ci-info: lo : 1 127.0.0.1 255.0.0.0 .
ci-info: eth1 : 0 . . 00:0d:3a:10:6a:53
route_info failed
Waiting for network configuration...
Waiting up to 60 more seconds for network configuration...
Booting system without full network configuration...
错误 2
ci-info: | eth0 | False | . | . | 00:0d:3a:21:f9:ad |
ci-info: +--------+-------+-----------+-----------+-------------------+
ci-info: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Route info failed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ i=eth0
+ x=0
+ ifdown eth0
ifdown: interface eth0 not configured
+ ifup eth0
Missing required variable: address
Missing required configuration variables for interface eth0/inet.
Failed to bring up eth0.
+ exit 0x\
解决方案
对于 CentOS
从 下的 /etc/sysconfig/network-script
ifcfg-eth0 文件中删除 HWADDR 指令。
对于 SUSE Linux
删除 下包含 eth0 或 eth1 /etc/udev/rules.d
条目的文件。
对于 Ubuntu
错误 1
此错误指示配置了 aneth1 接口而不是 eth0。 如果 VM 上的操作系统未安装 某些 udev 更新,则可能会出现这种情况。 在这种情况下, udev 错误地保存了以前的网络接口。 调整 VM 大小或移动 VM 时,它会收到一个不同的 MAC 地址,该地址将分配给 eth1。
注意
可以从串行日志中验证映像的版本。 如果找到 2014 年 1 月发布的 Ubuntu 内核 ((例如 3.2.0-58.88) ),则表示操作系统尚未更新。
若要解决此问题,请将 OS 磁盘附加到另一个正在运行的 VM,然后删除 下的 /etc/udev/rules.d/70-persistent-net.rules
udev 规则文件。
若要避免将来出现此问题,建议更新 VM 上的 udev 包。 例如,运行以下命令:
sudo apt-get update
sudo apt-get install udev
错误 2
若要解决此问题,请将 /etc/network/interfaces.d/eth0.cfg
文件重置为默认值,并使其请求 Azure DHCP 获取 IP 地址。 然后,删除文件夹中包含缓存的 DHCP 设置的文件 /var/lib/dhcp
。 下面是默认 eth0.cfg 文件的示例:
# The primary network interface
auto eth0
iface eth0 inet dhcp
解决自定义 Linux 操作系统上的问题
如果存在网络问题的 VM 使用上传的 VHD,可以尝试基于工作库映像配置网络。 为此,请将有问题的磁盘作为数据磁盘附加到库 VM,然后运行以下命令。
fdisk -l
df -h
mount /dev/sdc1 /temporary
df -h
cd /temporary/etc/udev/rules.d
ls -ltr
mv 70-persistent-net.rules /temporary/root/
cd ../../network
ls
mv interfaces interfaces.org
ls -ltr
从工作 VM 复制到当前文件夹文件:
cp /etc/network/interfaces .
cp -R /etc/network/interfaces
cp -R /etc/network/interfaces.d .
cp -R /etc/network/interfaces.dynamic.d .
ls -ltr
cd ..
cd
umount /mnt
有关如何将数据磁盘附加到库 VM 的详细信息,请参阅如何在 Azure 门户将数据磁盘附加到 Windows VM。
参考:操作系统的网络文件
网络卡配置
/etc/sysconfig/network-scripts/ifcfg-eth0 ..ifcfg-eth0:1 (Centos, Oracle)
/etc/sysconfig/network/ifcfg-eth0 (SuSE)
/etc/network/interfaces (Ubuntu)
主机名配置
/etc/sysconfig/network (Centos , Oracle)
/etc/HOSTNAME (SuSE)
/etc/hostname (Ubuntu)
DNS 配置文件
/etc/resolv.conf
/etc/nsswitch.conf
默认网关的配置文件
set in ifcfg-ethn or /etc/sysconfig/network
/etc/sysconfig/network/route (SuSE)
/etc/network/interfaces (Ubuntu)
静态路由
/etc/sysconfig/network-scripts/route-ethX (Centos, Oracle)
/etc/sysconfig/network/routes (SuSE)
/etc/network/interfaces (Ubuntu)
防火墙规则
/etc/sysconfig/iptables (centos, Oracle)
/etc/sysconfig/SuSEfirewall2.d/services (SuSE)
/etc/ufw/ufw.conf (Ubuntu)
联系我们寻求帮助
如果你有任何疑问或需要帮助,请创建支持请求或联系 Azure 社区支持。 还可以向 Azure 反馈社区提交产品反馈。
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈