拉起Qemu时配置指定IP

Note that from inside the guest, connecting to a port on the "gateway" IP address will connect to that port on the host; so for instance "ssh 10.0.2.2" will ssh from the guest to the host.

You can configure User Networking using the -netdev user command line option.

Adding the following to the qemu command line will change the network configuration to use 192.168.76.0/24 instead of the default (10.0.2.0/24) and will start guest DHCP allocation from 9 (instead of 15):

-netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9

You can isolate the guest from the host (and broader network) using the restrict option. For example -netdev user,id=mynet0,restrict=y or -netdev type=user,id=mynet0,restrict=yes will restrict networking to just the guest and any virtual devices. This can be used to prevent software running inside the guest from phoning home while still providing a network inside the guest. You can selectively override this using hostfwd and guestfwd options.

Advanced user networking options

The -netdev user parameter has some more useful options:

  • The DHCP address and name for the guest can be set with -netdev user,id=n0,host=addr,hostname=name
  • You can specify the guest-visible virtual DNS server address with -netdev user,id=n0,dns=addr
  • QEMU can simulate a TFTP server with -netdev user,id=n0,tftp=xxx,bootfile=yyy
  • To share files between your guest and host, you can use -netdev user,id=n0,smb=dir,smbserver=addr
  • To forward host ports to your guest, use -netdev user,id=n0,hostfwd=hostip:hostport-guestip:guestport

For details, please see the QEMU documentation.

./qemu-system-x86_64 -machine pc -enable-kvm -m 8G -smp 8 -cpu host \
-boot c -hda ./ubt20.04_10G.qcow2 \
-device edu \
-device e1000,netdev=net0 \
-netdev user,id=net0,net=192.168.76.0/24,dhcpstart=192.168.76.9 \
#-device remote-port,id=rp1 -machine-path /tmp/machine-x86 \
-monitor stdio

#socat stdin,raw,echo=11111111111111 unix-connect:/tmp/machine-x86/qemu-rport-_machine_peripheral_rp1

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
QEMU是一款开源的虚拟机软件,它可以模拟多种硬件环境来运行不同的操作系统。在QEMU配置虚拟机的网卡非常简单,以下是配置步骤: 1. 首先,需要创建一个虚拟机的镜像文件。可以使用qemu-img命令创建一个大小合适的空白镜像文件,例如: ``` qemu-img create -f qcow2 myimage.img 10G ``` 这将创建一个大小为10GB的qcow2格式的镜像文件。 2. 接下来,使用qemu命令启动虚拟机并指定镜像文件的路径。例如: ``` qemu-system-x86_64 -hda myimage.img ``` 这将启动一个x86_64架构的虚拟机,并将镜像文件myimage.img作为虚拟机的硬盘。 3. 默认情况下,QEMU会为虚拟机分配一个NAT网络,这意味着虚拟机可以访问外部网络,但无法从外部网络直接访问虚拟机。如果需要配置虚拟机的网卡以便与外部网络通信,则需要添加一个网桥。 4. 在宿主机上创建一个网桥设备,例如: ``` sudo brctl addbr br0 sudo ifconfig br0 up ``` 5. 将虚拟机的网卡(通常是第一个网卡)连接到网桥上,例如: ``` sudo brctl addif br0 eth0 sudo ifconfig eth0 up ``` 6. 最后,使用QEMU的命令行参数来指定虚拟机连接到网桥上的网卡,例如: ``` qemu-system-x86_64 -hda myimage.img -net nic -net bridge,br=br0 ``` 这将使虚拟机连接到网桥br0,并通过该网桥与外部网络通信。 以上步骤是在Linux系统上配置QEMU虚拟机网卡的简单示例,不同的操作系统和QEMU版本可能有所不同,但整体流程类似。通过配置虚拟机的网卡,可以使虚拟机与外部网络进行通信,并实现与宿主机之间的连接。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值