bersama catatan peribadi & teknikalnya.

Network Sharing for Qemu via WiFi

How To Set It Up with Tap Device

#tapdevice | #qemukvm
This is only applicable for having OpenBSD as Guest OS on Arch Linux as Host OS.

I created simple bash scripts for all the below steps and then executed them from the terminal:-

  1. Done in host OS: Create a tap device and allow permission to the user, set the device up, assign a manual ip address to be used by the guest OS (in my case, it is, and forward the ARP proxy to the tap device.
    sudo ip tuntap add dev tap0 mode tap user raihan group wheel
    sudo chown root.raihan /dev/net/tun
    sudo ip link set dev tap0 up
    sudo ip route add dev tap0
    sudo sysctl net.ipv4.conf.tap0.proxy_arp=1 net.ipv4.conf.wlp2s0.proxy_arp=1 net.ipv4.ip_forward=1
    #sudo sysctl net.ipv4.ip_forward=1 net.ipv6.conf.default.forwarding=1 net.ipv6.conf.all.forwarding=1
  2. Done in guest OS: Add the manual address that has previously been created in the host OS, and then add the IP address of the host's WLAN card as a default gateway to the guest OS, add the nameserver to resolv.conf file in /etc directory, and ping google to see if it succeeds.
    sudo ifconfig em0
    sudo route add default #(which would be the IP address of the host's wlan card)
    echo 'nameserver' >> /etc/resolv.conf
    ping -c 3
  3. Back to host OS: Set the firewall up for safety purposes.
    # Allow all outgoing traffic from the guest to the LAN or internet.
    sudo iptables -A FORWARD -i tap0 -o wlp2s0 -j ACCEPT
  4. Once the work in Qemu/KVM has finished, do not forget to set the loaded tap device down and delete it from the host OS.
    sudo ip route flush dev tap0
    sudo sysctl net.ipv4.conf.tap0.proxy_arp=0 net.ipv4.conf.wlp2s0.proxy_arp=0 net.ipv4.ip_forward=0
    #sudo sysctl net.ipv4.ip_forward=0 net.ipv6.conf.default.forwarding=0 net.ipv6.conf.all.forwarding=0
    sudo ip link set dev tap0 down
    sudo ip link del dev tap0
    sudo ip tuntap del dev tap0 mode tap

Kali terakhir dikemaskini: