Arm 无法SSH到运行dropbear sshd的QEMU虚拟机

Arm 无法SSH到运行dropbear sshd的QEMU虚拟机,arm,embedded,embedded-linux,qemu,dropbear,Arm,Embedded,Embedded Linux,Qemu,Dropbear,我已经建立了一个模拟vexpress-a9机器的QEMU虚拟机。我使用buildroot创建了initrd系统,还使用了buildroot在安装过程中下载的codesourcery交叉编译器编译Linux内核。这就是我调用qemu的方式 qemu系统arm-m 512-m vexpress-a9 -dtb linux-4.4.192/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -内核linux-4.4.192/arch/arm/boot/zImage -init

我已经建立了一个模拟vexpress-a9机器的QEMU虚拟机。我使用buildroot创建了initrd系统,还使用了buildroot在安装过程中下载的codesourcery交叉编译器编译Linux内核。这就是我调用qemu的方式

qemu系统arm-m 512-m vexpress-a9
-dtb linux-4.4.192/arch/arm/boot/dts/vexpress-v2p-ca9.dtb
-内核linux-4.4.192/arch/arm/boot/zImage
-initrd buildroot/output/images/rootfs.cpio
-追加“控制台=ttyAMA0,ip=dhcp”
-网络网卡,型号=lan9118
-net用户,hostfwd=tcp::2222-:22
-无图形

很好。网络相关启动消息,告知网络已初始化,dropbear sshd已启动并运行:

启动网络:正常
启动dropbear sshd:random:dropbear:uninitialized urandom读取(读取32字节,1位熵可用)
好的

但是,必须手动为
eth0
接口分配IP。我在与Linux主机相同的子网中为其分配了一个未使用的C类地址,如下所示:

# ssh root@127.0.0.1
random: ssh: uninitialized urandom read (32 bytes read, 24 bits of entropy available)
random: dropbear: uninitialized urandom read (32 bytes read, 24 bits of entropy available)
random: dropbear: uninitialized urandom read (32 bytes read, 24 bits of entropy available)
random: dropbear: uninitialized urandom read (32 bytes read, 24 bits of entropy available)

Host '127.0.0.1' is not in the trusted hosts file.
(ecdsa-sha2-nistp256 fingerprint sha1!! de:cf:f8:b3:ac:4d:96:47:22:d7:76:a1:ea:11:3d:bc:ec:c6:71:9a)
Do you want to continue connecting? (y/n) y
root@127.0.0.1's password:
random: dropbear: uninitialized urandom read (32 bytes read, 26 bits of entropy available)
#ifconfig eth0 192.168.160.150以上
smsc911x 4e000000.eth0:smsc911x/921x标识为0xa12a0000,IRQ:31

因此,
ifconfig
现在显示:

# ifconfig
eth0      Link encap:Ethernet  HWaddr 52:54:00:12:34:56
          inet addr:192.168.160.150  Bcast:192.168.160.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:31

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
netstat
告诉我我们正在监听端口22:

# netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
我甚至可以ssh到localhost,如下所示:

# ssh root@127.0.0.1
random: ssh: uninitialized urandom read (32 bytes read, 24 bits of entropy available)
random: dropbear: uninitialized urandom read (32 bytes read, 24 bits of entropy available)
random: dropbear: uninitialized urandom read (32 bytes read, 24 bits of entropy available)
random: dropbear: uninitialized urandom read (32 bytes read, 24 bits of entropy available)

Host '127.0.0.1' is not in the trusted hosts file.
(ecdsa-sha2-nistp256 fingerprint sha1!! de:cf:f8:b3:ac:4d:96:47:22:d7:76:a1:ea:11:3d:bc:ec:c6:71:9a)
Do you want to continue connecting? (y/n) y
root@127.0.0.1's password:
random: dropbear: uninitialized urandom read (32 bytes read, 26 bits of entropy available)
然而,从主机上,当我尝试从linux主机SSH到这个VM时,我看到了这一点:

$ ssh -vvv root@192.168.160.150
OpenSSH_7.4p1 Debian-10+deb9u7, OpenSSL 1.0.2s  28 May 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "192.168.160.150" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 192.168.160.150 [192.168.160.150] port 22.
debug1: connect to address 192.168.160.150 port 22: No route to host
ssh: connect to host 192.168.160.150 port 22: No route to host
我很高兴有一些关于这方面的建议,因为我找不到其他可以尝试的

更新1:在配置buildroot时包含dhcpd。现在,无论我使用dropbear还是openssh,日志消息都会一直显示到

Starting dhcpcd...
no interfaces have a carrier <--- the problem
forked to background, child pid 746
smsc911x 4e000000.ethernet eth0: SMSC911x/921x identified at 0xa12a0000, IRQ: 31
Starting dropbear sshd: random: dropbear: uninitialized urandom read (32 bytes read, 2 bits of entropy available)
OK
random: dhcpcd: uninitialized urandom read (120 bytes read, 2 bits of entropy available)

但是,主机仍然无法访问该计算机。是否需要从主机向此VM添加手动路由?如果是,我怎么做?QEMU是否在主机上创建虚拟接口(与工作站一样)?

如果使用QEMU的“用户”模式网络,则尝试在主机网络中为来宾分配IP地址是错误的。用户模式网络使用自己的DHCP服务器创建了一个小型模拟网络——您可以在

默认情况下,来宾所处的网络是10.0.2.x,但您可以使用命令行参数对其进行更改

配置来宾的最简单方法是让它运行DHCP客户端,该客户端应该能够找到QEMU提供的内置DHCP服务器,并通过这种方式在模拟网络上获得IP地址

关于用户模式网络的一个重要问题是,它不允许您从主机直接连接到来宾VM。连接到它的唯一方法是,如果QEMU命令行指定要从主机转发到来宾的特定端口——如果这样做,则可以连接到在命令行转发选项中指定的主机IP地址和端口,并将其转发到模拟网络上来宾的IP地址和端口


如果这还不够,并且您需要虚拟机出现在桥接到主机网络的真实虚拟界面上,那么您应该停止使用用户模式网络,转而使用TAP网络选项。不过,TAP的设置更为复杂。

我昨天花了几个小时尝试了不同的选项(即
-net
-netdev
)和
qemu系统arm
,但最后奏效的是这一选项:
-nic用户,hostfwd=:2222-:22
,这是我从(查看替换的
-redir
选项)。我还必须在主机的SSH配置文件中添加这3行代码:
/etc/SSH/SSH\u config

Host localhost
PreferredAuthentications=password
PubkeyAuthentication=no

没有在内核命令行参数中传递'ip=dhcp',告诉来宾从内置dhcp服务器(在本例中由qemu提供)查找地址??那么为什么dmesg没有告诉我们这方面的任何信息?为什么界面仍然没有地址?请查看更新并让我知道我是否朝着正确的方向前进ip=dhcp是否工作,或者界面是否默认出现是来宾操作系统/发行版配置问题——这取决于来宾中的软件来完成QEMU提供的模拟硬件是正确的。根据我的更新2,接口由内置QEMU dhcp服务器获取IP地址。它仍然无法从外部访问。你知道如何使VM可访问吗?我在回答中添加了几段关于这一点的内容——基本上,如果你的主机中有正确的hostfwd选项然后,主机上的命令行“ssh-p2222localhost”应该将您连接到来宾机上的端口22。