sudo apt-get install bridge-utils uml-utilities
//查看Ubuntu系统的eth
root@richard-virtual-machine:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:5a:d8:65 brd ff:ff:ff:ff:ff:ff
inet 192.168.2.184/24 brd 192.168.2.255 scope global dynamic eno16777736
valid_lft 7043sec preferred_lft 7043sec
inet6 fe80::20c:29ff:fe5a:d865/64 scope link
valid_lft forever preferred_lft forever
root@richard-virtual-machine:~# dmesg | grep -i eth
[ 1.976873] e1000 0000:02:01.0 eth0: (PCI:66MHz:32-bit) 00:0c:29:5a:d8:65
[ 1.976879] e1000 0000:02:01.0 eth0: Intel(R) PRO/1000 Network Connection
[ 1.986531] e1000 0000:02:01.0 eno16777736: renamed from eth0
# 修改ubuntu主机的网络配置文件 /etc/network/interfaces
root@richard-virtual-machine:~# sudo gedit /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto eno16777736
iface eno16777736 inet dhcp
#auto br0
iface br0 inet dhcp
bridge_ports eno16777736
bridge_maxwait 0
# 创建QEMU的网络接口启动脚本,重启网络使配置生效
root@richard-virtual-machine:~# sudo gedit /etc/network/interfaces
(gedit:92752): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files
root@richard-virtual-machine:~# sudo gedit /etc/qemu-ifup
(gedit:92831): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files
//在脚本文件/etc/qemu-ifup中写入如下的内容:
#!/bin/sh
echo "Executing /etc/qemu-ifup"
echo "Bringing $1 for bridged mode..."
sudo /sbin/ifconfig $1 0.0.0.0 promisc up
echo "Adding $1 to br0..."
sudo /sbin/brctl addif br0 $1
sleep 3
# 保存 文件/etc/qemu-ifup 以后,赋予文件/etc/qemu-ifup 可执行权限,然后重启网络使所有的配置生效。
root@ubuntu:~# sudo chmod a+x /etc/qemu-ifup
//重启网络使配置生效
root@richard-virtual-machine:~# sudo /etc/init.d/networking restart
[ ok ] Restarting networking (via systemctl): networking.service.
#启动桥连网络
root@richard-virtual-machine:~# sudo ifdown eno16777736
Killed old client process
Internet Systems Consortium DHCP Client 4.3.1
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/eno16777736/00:0c:29:5a:d8:65
Sending on LPF/eno16777736/00:0c:29:5a:d8:65
Sending on Socket/fallback
DHCPRELEASE on eno16777736 to 192.168.2.1 port 67 (xid=0x1149c5ea)
root@richard-virtual-machine:~# sudo ifup br0
Internet Systems Consortium DHCP Client 4.3.1
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/br0/00:0c:29:5a:d8:65
Sending on LPF/br0/00:0c:29:5a:d8:65
Sending on Socket/fallback
DHCPDISCOVER on br0 to 255.255.255.255 port 67 interval 3 (xid=0xde368f31)
DHCPREQUEST of 192.168.2.183 on br0 to 255.255.255.255 port 67 (xid=0x318f36de)
DHCPOFFER of 192.168.2.183 from 192.168.2.1
DHCPACK of 192.168.2.183 from 192.168.2.1
bound to 192.168.2.183 -- renewal in 3486 seconds.
root@richard-virtual-machine:~# ifconfig -a
br0 Link encap:以太网 硬件地址 00:00:00:00:00:00
UP BROADCAST MULTICAST MTU:1500 跃点数:1
接收数据包:7 错误:0 丢弃:0 过载:0 帧数:0
发送数据包:8 错误:0 丢弃:0 过载:0 载波:0
碰撞:0 发送队列长度:0
接收字节:1157 (1.1 KB) 发送字节:1054 (1.0 KB)
eno16777736 Link encap:以太网 硬件地址 00:0c:29:5a:d8:65
inet 地址:192.168.2.183 广播:192.168.2.255 掩码:255.255.255.0
inet6 地址: fe80::20c:29ff:fe5a:d865/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1
接收数据包:876201 错误:0 丢弃:0 过载:0 帧数:0
发送数据包:257164 错误:0 丢弃:0 过载:0 载波:0
碰撞:0 发送队列长度:1000
接收字节:1276194225 (1.2 GB) 发送字节:18046092 (18.0 MB)
lo Link encap:本地环回
inet 地址:127.0.0.1 掩码:255.0.0.0
inet6 地址: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 跃点数:1
接收数据包:2353 错误:0 丢弃:0 过载:0 帧数:0
发送数据包:2353 错误:0 丢弃:0 过载:0 载波:0
碰撞:0 发送队列长度:0
接收字节:158317 (158.3 KB) 发送字节:158317 (158.3 KB)
(注意:这里的bro是没有inet 地址的,貌似有点问题,当然,这是我后来发现的)
# 运行 qemu-mips 32的虚拟机
// 虚拟机下载网址:https://people.debian.org/~aurel32/qemu/
root@richard-virtual-machine:~# sudo qemu-system-mips -M malta -kernel vmlinux-2.6.32-5-4kc-malta -hda debian_squeeze_mips_standard.qcow2 -append "root=/dev/sda1 console=tty0" -net nic,macaddr=00:16:3e:00:00:01 -net tap -nographic
Executing /etc/qemu-ifup
Bringing tap0 for bridged mode...
Adding tap0 to br0...
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Linux version 2.6.32-5-4kc-malta (Debian 2.6.32-48squeeze4) (dannf@debian.org) (gcc version 4.3.5 (Debian 4.3.5-4) ) #1 Tue Sep 24 00:02:22 UTC 2013
[ 0.000000]
[ 0.000000] LINUX started...
[ 0.000000] bootconsole [early0] enabled
[ 0.000000] CPU revision is: 00019300 (MIPS 24Kc)
[ 0.000000] FPU revision is: 00739300
[ 0.000000] Determined physical RAM map:
[ 0.000000] memory: 00001000 @ 00000000 (reserved)
[ 0.000000] memory: 000ef000 @ 00001000 (ROM data)
[ 0.000000] memory: 005b7000 @ 000f0000 (reserved)
[ 0.000000] memory: 07958000 @ 006a7000 (usable)
[ 0.000000] Wasting 54496 bytes for tracking 1703 unused pages
[ 0.000000] Initrd not found or empty - disabling initrd
[ 0.000000] Zone PFN ranges:
[ 0.000000] DMA 0x00000000 -> 0x00001000
[ 0.000000] Normal 0x00001000 -> 0x00007fff
[ 0.000000] Movable zone start PFN for each node
[ 0.000000] early_node_map[1] active PFN ranges
[ 0.000000] 0: 0x00000000 -> 0x00007fff
[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32511
[ 0.000000] Kernel command line: root=/dev/sda1 console=tty0
[ 0.000000] PID hash table entries: 512 (order: -1, 2048 bytes)
[ 0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
[ 0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
[ 0.000000] Primary instruction cache 2kB, VIPT, 2-way, linesize 16 bytes.
[ 0.000000] Primary data cache 2kB, 2-way, VIPT, no aliases, linesize 16 bytes
[ 0.000000] Writing ErrCtl register=00000000
[ 0.000000] Readback ErrCtl register=00000000
[ 0.000000] Memory: 122952k/124256k available (3999k kernel code, 1128k reserved, 1084k data, 212k init, 0k highmem)
[ 0.000000] SLUB: Genslabs=7, HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[ 0.000000] Hierarchical RCU implementation.
[ 0.000000] NR_IRQS:256
[ 0.000000] CPU frequency 200.00 MHz
[ 0.000000] Console: colour dummy device 80x25
[ 0.000000] console [tty0] enabled, bootconsole disabled
Debian GNU/Linux 6.0 debian-mips ttyS0
而后登录debian-mips虚拟机:
root@debian-mips:~# ifconfig -a
eth1 Link encap:Ethernet HWaddr 00:16:3e:00:00:01
BROADCAST 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:10 Base address:0x1020
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:560 (560.0 B) TX bytes:560 (560.0 B)
//通过 ifconfig 命令得到网络接口名称为 "eth1" 。因此需要 编辑 mips虚拟机 的 /etc/network/interfaces文件,修改网络接口的名称。
//修改之后为如下:
root@debian-mips:~# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth1
iface eth1 inet dhcp
使用 ifup 命令启用 eth1 网络接口(这里终于出了问题,可能跟上面宿主机里面的br0有关系)
root@debian-mips:~# ifup eth1
Internet Systems Consortium DHCP Client 4.1.1-P1
Copyright 2004-2010 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/eth1/00:16:3e:00:00:01
Sending on LPF/eth1/00:16:3e:00:00:01
Sending on Socket/fallback
DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 6
DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 9
DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 14
DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 8
DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 14
DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 10
No DHCPOFFERS received.
No working leases in persistent database - sleeping.
//再次查看ip,这里也出现了问题eth1的inet addr “消失”了
root@debian-mips:~# ifconfig -a
eth1 Link encap:Ethernet HWaddr 00:16:3e:00:00:01
inet6 addr: fe80::216:3eff:fe00:1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:2520 (2.4 KiB)
Interrupt:10 Base address:0x1020
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:560 (560.0 B) TX bytes:560 (560.0 B)
//显然这里虚拟机 网络是无法ping通的;但是宿主机却是可以与外界ping通的
root@debian-mips:~# ping www.baidu.com
ping: unknown host www.baidu.com
问题:我这里的mips的网络配置哪里出了问题,还请大佬指导一波