Skip to content

Instantly share code, notes, and snippets.

@artembeloglazov
Forked from EmbeddedAndroid/qemu-ifup
Last active August 4, 2020 07:32
Show Gist options
  • Save artembeloglazov/db8c16efc91443955fca to your computer and use it in GitHub Desktop.
Save artembeloglazov/db8c16efc91443955fca to your computer and use it in GitHub Desktop.
Mac OSX (10.8.X) scripts for QEMU/KVM bridged networking with nat on en1.
#!/bin/bash
echo "Executing /etc/qemu-ifdown"
echo "Bringing TAP interface down"
ifconfig $1 down
echo "Removing interfaces"
ifconfig bridge0 deletem en1 deletem $1
echo "Bring down bridge"
ifconfig bridge0 down
echo "Removing bridge"
ifconfig bridge0 destroy
sysctl -w net.link.ether.inet.proxyall=0
sysctl -w net.inet.ip.forwarding=0
sysctl -w net.inet.ip.fw.enable=0
echo "Removing ipfw rule"
ipfw del `ipfw list | grep 'ip from any to any via en1' | sed -e 's/ .*//g'`
echo "Stop natd"
killall -9 natd
#!/bin/bash
echo "Executing /etc/qemu-ifup"
echo "Creating bridge"
sysctl -w net.link.ether.inet.proxyall=1
sysctl -w net.inet.ip.forwarding=1
sysctl -w net.inet.ip.fw.enable=1
ifconfig bridge0 create
echo "Bringing up $1 for bridged mode"
#Get the number of interface
num=`echo $1 | sed 's/tap//'`
ifconfig $1 192.168.2.1$num up
echo "Add $1 to bridge"
ifconfig bridge0 addm en1 addm $1
echo "Bring up bridge"
ifconfig bridge0 up
echo "Starting Natd on en1"
natd -interface en1
echo "Writing ipfw rule"
ipfw add divert natd ip from any to any via en1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment