mirror of
https://bitbucket.org/mangelo/snippets.git
synced 2024-11-22 02:41:00 +02:00
66 lines
2.1 KiB
Plaintext
66 lines
2.1 KiB
Plaintext
### Connect a qemu guest to real network.
|
|
|
|
* Guest: Debian GNU/Linux - eth0
|
|
* Host: Debian GNU/Linux - eth0.201
|
|
|
|
guest host host host
|
|
eth0 <---> tap0 <---> bridge0 <---> eth0.201 <---> real network
|
|
|
|
* One time:
|
|
apt-get install bridge-utils
|
|
apt-get install uml-utilities
|
|
apt-get install vlan
|
|
|
|
* Bridge connection with vlan
|
|
As root:
|
|
vconfig add eth0 201
|
|
tunctl -t tap0 -u username
|
|
brctl addbr bridge0
|
|
brctl stp bridge0 off
|
|
brctl addif bridge0 eth0.201
|
|
brctl addif bridge0 tap0
|
|
ifconfig eth0.201 up
|
|
ifconfig tap0 up
|
|
ifconfig bridge0 up
|
|
|
|
* Bridge connection to physical interface
|
|
As root:
|
|
tunctl -t tap0 -u username
|
|
ifconfig eth0 0.0.0.0
|
|
brctl addbr bridge0
|
|
brctl stp bridge0 off
|
|
brctl addif bridge0 eth0
|
|
brctl addif bridge0 tap0
|
|
ifconfig eth0 up
|
|
ifconfig tap0 up
|
|
ifconfig bridge0 192.168.45.X netmask 255.255.255.0 up
|
|
route add default gw 192.168.45.Z
|
|
|
|
* NAT connection
|
|
As root:
|
|
tunctl -t tap0 -u username
|
|
ifconfig tap0 192.168.45.1 netmask 255.255.255.0 up
|
|
echo 1 > /proc/sys/net/ipv4/ip_forward
|
|
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
|
|
|
|
* As normal user, run the qemu guest:
|
|
qemu-system-x86_64 \
|
|
-name DEVICE1 \
|
|
-m 512 \
|
|
-smp cpus=1 \
|
|
-enable-kvm \
|
|
-hda device1.qcow2 \
|
|
-serial telnet::2000,server,nowait \
|
|
-monitor tcp:127.0.0.1:4000,server,nowait \
|
|
-display none \
|
|
-daemonize \
|
|
-net none \
|
|
-net nic,model=e1000,vlan=1,macaddr=00:01:00:ff:01:01 \
|
|
-net nic,model=e1000,vlan=2,macaddr=00:01:00:ff:01:02 \
|
|
-net nic,model=e1000,vlan=3,macaddr=00:01:00:ff:01:03 \
|
|
-net nic,model=e1000,vlan=4,macaddr=00:01:00:ff:01:04 \
|
|
-net tap,vlan=1,ifname=tap0,script=no,downscript=no \
|
|
-net socket,vlan=2,udp=127.0.0.1:9012,localaddr=:9002 \
|
|
-net socket,vlan=3,udp=127.0.0.1:9013,localaddr=:9003 \
|
|
-net socket,vlan=4,udp=127.0.0.1:9014,localaddr=:9004
|