Skip to content

Instantly share code, notes, and snippets.

@milisarge
Last active February 6, 2022 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milisarge/557e539f24f6eef81550c915fd36cd55 to your computer and use it in GitHub Desktop.
Save milisarge/557e539f24f6eef81550c915fd36cd55 to your computer and use it in GitHub Desktop.
Qemu sanal köprülü ağ kurma

Aşağıda yer alan komutlar sanal bir qemu köprülü ağı kurmak içindir. Ana bilgisayar koşuğlara sanal ip aralığı üzerinden erişebilir.

gerekli uygulamalar

qemu, vde2, dnsmasq

qemu-vde.sh vde tap ağı kurmak için gerekli betik

#!/bin/sh
# QEMU/VDE network environment preparation script

# The IP configuration for the tap device that will be used for
# the virtual machine network:

TAP_DEV=tap0
TAP_IP=192.168.100.1
TAP_MASK=24
TAP_NETWORK=192.168.100.0

# Host interface
NIC=wlp2s0

case "$1" in
  start)
	echo -n "Starting VDE network for QEMU: "

	# If you want tun kernel module to be loaded by script uncomment here
	#modprobe tun 2>/dev/null
	## Wait for the module to be loaded
	#while ! lsmod | grep -q "^tun"; do echo "Waiting for tun device"; sleep 1; done

	# Start tap switch
	vde_switch -tap "$TAP_DEV" -daemon -mod 660 -group users

	# Bring tap interface up
	ip address add "$TAP_IP"/"$TAP_MASK" dev "$TAP_DEV"
	ip link set "$TAP_DEV" up

	# Start IP Forwarding
	echo "1" > /proc/sys/net/ipv4/ip_forward
	iptables -t nat -A POSTROUTING -s "$TAP_NETWORK"/"$TAP_MASK" -o "$NIC" -j MASQUERADE
	;;
  stop)
	echo -n "Stopping VDE network for QEMU: "
	# Delete the NAT rules
	iptables -t nat -D POSTROUTING -s "$TAP_NETWORK"/"$TAP_MASK" -o "$NIC" -j MASQUERADE

	# Bring tap interface down
	ip link set "$TAP_DEV" down

	# Kill VDE switch
	pgrep vde_switch | xargs kill -TERM
	;;
  restart|reload)
	$0 stop
	sleep 1
	$0 start
	;;
  *)
	echo "Usage: $0 {start|stop|restart|reload}"
	exit 1
esac
exit 0

qemu-vde ağı başlatılır.

qemu-vde.sh start

dnsmasq.conf

interface=tap0
port=5353
listen-address=127.0.0.1
dhcp-range=192.168.100.100,192.168.100.150,12h
# server=8.8.8.8

mevcut vde ağına birimleri bağlar ve dns/dhcp servisi sağlar.

# bu komut iptal - non-root durum için ama gerekli işlevi sağlamadı.
# slirpvde -d -n 192.168.100.0 -dhcp
# -d debug mode, non-daemon
sudo dnsmasq -C dnsmasq.conf -d

sanal makinelerin bağlanması

# node1 - 192.168.100.135
qemu-system-riscv64 -machine virt \
-netdev vde,id=n1 -device virtio-net-device,netdev=n1,mac=fc:ac:14:e8:8f:32 -net vde \
-cpu rv64 -m 48 -smp 1 -bios none \
-kernel build-qemu-virt-riscv64-test-my/lk.elf
# node2 - 192.168.100.136
qemu-system-riscv64 -machine virt \
-netdev vde,id=n1 -device virtio-net-device,netdev=n1,mac=fc:ac:14:e8:8f:33 -net vde \
-cpu rv64 -m 48 -smp 1 -bios none \
-kernel build-qemu-virt-riscv64-test-my/lk.elf

referanslar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment