I created simple bash
scripts for all the below steps and then executed them from the terminal:-
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 192.168.1.2
), and forward the ARP proxy to the tap device.#!/bin/sh
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 192.168.1.2 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
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.#!/bin/sh
sudo ifconfig em0 192.168.1.2
sudo route add default 192.168.1.6 #(which would be the IP address of the host's wlan card)
echo 'nameserver 192.168.1.1' >> /etc/resolv.conf
ping -c 3 www.google.com
host
OS: Set the firewall up for safety purposes.#!/bin/sh
# Allow all outgoing traffic from the guest to the LAN or internet.
sudo iptables -A FORWARD -i tap0 -o wlp2s0 -j ACCEPT
Qemu/KVM
has finished, do not forget to set the loaded tap
device down and delete it from the host
OS.#!/bin/sh
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