-
Notifications
You must be signed in to change notification settings - Fork 164
/
wifi-to-eth-bridge.sh
executable file
·70 lines (56 loc) · 1.83 KB
/
wifi-to-eth-bridge.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# Bridge WiFi with Ethernet
# Internet source is wlan0
# wpa_supplicant will be running on wlan0
#
# This is Layer 3 proxy arp solution
#
# This script is made to work with Raspbian Stretch
# but it can be used with most of the distributions
# by making few changes.
#
# Make sure you have already installed:
# avahi-daemon
# parprouted
# dhcp-helper
#
# Just install these packages and don't touch
# any configuration file. This script will handle
# required options dynamically.
#
# Configure your wpa_supplicant prior to this script
#
eth="eth0"
wlan="wlan0"
sudo systemctl start network-online.target &> /dev/null
sudo iptables -F
sudo iptables -t nat -F
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
echo "Killing parprouted "
sudo killall parprouted &> /dev/null
echo "Stopping dhcp-helper service"
sudo systemctl stop dhcp-helper
echo "Killing dhcp-helper"
sudo killall dhcp-helper &> /dev/null
echo "Stopping avahi-daemon service"
sudo systemctl stop avahi-daemon
echo "Killing avahi-daemon"
sudo killall avahi-daemon &> /dev/null
echo "Creating temp avahi conf file"
cp /etc/avahi/avahi-daemon.conf /tmp/avahi-daemon.conf
sed -i s/^enable-reflector=no/enable-reflector=yes/ /tmp/avahi-daemon.conf
option=$(cat /tmp/avahi-daemon.conf | grep enable-reflector=yes)
if [ $option=="" ]; then
echo -e '\n[reflector]\nenable-reflector=yes\n' >> /tmp/avahi-daemon.conf
fi
echo "Starting parprouted ..."
sudo /usr/sbin/parprouted $eth $wlan &
echo "Starting dhcp-helper ..."
sudo /usr/sbin/dhcp-helper -r /var/run/dhcp-helper.pid -b $wlan &
echo "Flushing $eth IP addr"
sudo ip addr flush dev $eth
echo "Assigning IP to $eth from $wlan"
sudo /sbin/ip addr add $(/sbin/ip addr show $wlan | perl -wne 'm|^\s+inet (.*)/| && print $1')/32 dev $eth &
sleep 2
echo "Starting avahi-daemon ... "
sudo avahi-daemon -f /tmp/avahi-daemon.conf &