1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #!/usr/bin/env bash
- set -euo pipefail # bash strict mode
- bridgename=br0
- tapinterface=tap0
- outinterface=eth1
- if [ "x$1" != "x" ] ; then
- outinterface="$1"
- fi
- ifaces=`awk -F: '{print $1}' /proc/net/dev | tail -n +3`
- iffound="0"
- for i in $ifaces
- do
- if [ "$outinterface" == "$i" ] ; then
- iffound="1"
- fi
- done
- if [ "$iffound" == "0" ] ; then
- echo
- echo "Can't find the output interface."
- echo
- exit 1
- fi
- outifaceip=`ifconfig | grep -A1 $outinterface | tail -1 | awk -F: '{print $2}' | awk '{print $1}'`
- outifaceiptokens=`echo $outifaceip | awk -F \. '{print NF}'`
- if [ "$outifaceiptokens" != "4" ] ; then
- echo
- echo "The selected output interface $outinterface doesn't seem to have a valid IP address."
- echo
- exit 1
- fi
- hostaddress="192.168.1.1"
- guestaddress="192.168.1.95"
- sudo tunctl -t $tapinterface
- sudo brctl addbr $bridgename
- sudo brctl addif $bridgename $tapinterface
- sudo ip link set $bridgename up
- sudo ip addr add $hostaddress/24 dev $bridgename
- sudo route add -host $guestaddress dev $bridgename
- sudo parprouted eth1 $bridgename
- sudo ~/scripts/ip-router.sh $outinterface
|