1. 安裝套件
sudo apt-get install bridge-utils uml-utilities
2. 常用brctl 橋接指令,需要root權限
brctl help brctl show brctl addbr [Bridge Name] brctl addif [Interface Name] brctl delbr [Bridge Name] brctl delif [Interface Name]
3. 建立橋接網路br0
sudo brctl addbr br0
4. 將 br0 橋接給 eth0 使用
sudo brctl addif br0 eth0
5.設定網路
sudo vi /etc/network/interfaces ## 說明 # # -> eth0 -> 實體機 # Internet -> br0 -> # -> br1 -> N 個虛擬機 # # The loopback network interface auto lo iface lo inet loopback iface eth0 inet manual ## interent -> br0 -> eth0 -> 實體機 auto br0 iface br0 inet static address [本機 ip] netmask [本機 netmask] gateway [本機 gateway] bridge_ports eth0 bridge_fd 9 bridge_hello 2 bridge_maxage 12 bridge_stp off ## interent -> br0 -> br1 -> 虛擬機 auto br1 iface br1 inet static address 192.168.1.1 netmask 255.255.255.0 gateway [本機 ip] bridge_ports tap0 bridge_fd 9 bridge_hello 2 bridge_maxage 12 bridge_stp off
6. 重啟動網路
ifconfig eth0 down ifconfig eth0 up /etc/init.d/netwroking restart
7. 查看網路連線
ifconfig route -n ping gateway ping 8.8.8.8
8. 設定防火牆 iptables (ROOT)
echo 1 > /proc/sys/net/ipv4/ip_forward
### 下面的 br1 要看上面連虛擬機的 Bridge 設多少
iptables -A INPUT -i br1 -j ACCEPT iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE
9. 開啟 DHCP 服務
可以參考文章 DHCP Server 來安裝設定。
10. 開虛擬機連上網路
下面的 OS.img 檔案,可以參考文章建立一個 arm.img 並且可以用虛擬機開機 來建立!
qemu-system-x86_64 -enable-kvm \ -cpu host \ -smp 4 \ -m 6000 \ -hda OS.img \ -boot c \ -net nic \ -net bridge,br=br1 &
------------------- Debug -------------------
# Question 1Could not access KVM kernel module: No such file or directory failed to initialize KVM: No such file or directory Back to tcg accelerator. qemu: could not load PC BIOS 'bios.bin'
# Solution 1
sudo apt-get install seabios sudo cd /usr/local/share/qemu sudo ln -sf /usr/share/seabios/*.bin .
-----------------------------------------------------------------------------
# Question 2
failed to create tun device: Operation not permitted failed to launch bridge helper qemu-system-x86_64: -net bridge,br=br10: Device 'bridge' could not be initialized
qemu-bridge-helper 需要有 root 的權限才能執行
# Solution 2
chmod u+s /usr/local/libexec/qemu-bridge-helper
------------------------------------------------------------------------------
# Question 3
failed to initialize KVM: No such file or directory Back to tcg accelerator.
# Solution 3
忘了…
-------------------------------------------------------------------
# Question 4
failed to parse default acl file `/usr/local/etc/qemu/bridge.conf' failed to launch bridge helper
# Solution 4
vi /usr/local/etc/qemu/bridge.conf -> allow br1
---------------------------------------------------------------------
# Question 5
Could not access KVM kernel module: Permission denied failed to initialize KVM: Permission denied
# Solution 5
建立 kvm 群組:
groupadd kvm
將自己的使用者 $USER 加到 kvm 群組中:
usermod -a -G kvm $USER
調整 /dev/kvm 使用者權限
chown root:kvm /dev/kvm chmod 660 /dev/kvm
重新載入 kvm 驅動模組
rmmod kvm_intel kvm modprobe kvm_intel kvm
# 如果還是不行,就請重新開機再試試
shutdown -r now
---------------------------------------------------------------------
# Question 6
qemu-system-x86_64: symbol lookup error: qemu-system-x86_64: undefined symbol: libusb_get_port_numbers
# Solution 6
先確認 libusb-1.0 有無安裝,版本對不對,再做以下指令重新連結:
sudo ln -sf /lib/x86_64-linux-gnu/libusb-1.0.so.0 /usr/local/lib/libusb-1.0.so.0
沒有留言:
張貼留言