1、安装app-emulation/qemu、sys-apps/usermode-utilities、net-misc/bridge-utils、app-emulation/libvirt
2、配置/etc/conf.d/net文件
1)vi /etc/conf.d/net
# Interface tap0
config_tap0=null
tuntap_tap0="tap"
# Interface br0
config_br0="192.168.1.1/24"
bridge_br0="tap0"
rc_net_br0_need="net.tap0"
2)设置br0和tap0接口
cd /etc/init.d
ln -s net.lo net.tap0
ln -s net.lo net.br0
rc-update add net.br0 default
/etc/init.d/net.br0 start
3、设置转发和防火墙
1)开启转发
vi /etc/sysctl.conf
net.ipv4.ip_forward=1
sysctl -p
2)设置防火墙
rc-update add iptables default
iptables -A FORWARD -i br0 -o wlan0 -j ACCEPT
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -i wlan0 -o br0 -m state --state RELATED,ESTABLISHED -j ACCEPT
rc-service iptables save
4、DNS局域网设置
1)安装dnsmasq
2)编辑/etc/dnsmasq.conf
# We want dnsmasq to listen on br0 interface.
interface=br0 # We provide a dhcp range for dnsmasq
dhcp-range=192.168.1.50,192.168.1.150,12h
3)开启服务
/etc/init.d/dnsmasq start
5、设置qemu脚本
#!/bin/sh
# This script created by AQEMU
/usr/bin/qemu-system-x86_64 -enable-kvm \
-cpu host \
-m 2048M \
-drive file=/home/cw/Documents/qemu/CentOS/CentOS.img,if=virtio \
-boot once=c,menu=off \
-netdev tap,ifname=tap0,script=no,downscript=no,id=mynet0 -device virtio-net,netdev=mynet0,mac=82:e9:67:33:ad:d0 \
-rtc base=localtime \
-monitor stdio \
-name "centos" \
$@
本文分享自微信公众号 - Linux那些事儿(chenwei19900230)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
来源:oschina
链接:https://my.oschina.net/u/4612048/blog/4487266