-
Notifications
You must be signed in to change notification settings - Fork 164
/
eth-to-wifi-route.sh
executable file
·89 lines (73 loc) · 2.04 KB
/
eth-to-wifi-route.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# Share Eth with WiFi Hotspot
#
# This script is created 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 `dnsmasq` and `hostapd`
# Please modify the variables according to your need
# Don't forget to change the name of network interface
# Check them with `ifconfig`
ip_address="192.168.2.1"
netmask="255.255.255.0"
dhcp_range_start="192.168.2.2"
dhcp_range_end="192.168.2.100"
dhcp_time="12h"
eth="eth0"
wlan="wlan0"
ssid="Raspberry-Hotspot"
psk="raspberry"
which dnsmasq > /dev/null
if [ $? = 1 ]
then
echo "Please install dnsmasq"
echo " $ sudo apt-get install dnsmasq"
exit 1
fi
which hostapd > /dev/null
if [ $? = 1 ]
then
echo "Please install hostapd"
echo " $ sudo apt-get install hostapd"
exit 1
fi
echo "Dependencies installed"
sudo killall wpa_supplicant &> /dev/null
sudo rfkill unblock wlan &> /dev/null
sleep 2
sudo systemctl start network-online.target
sudo iptables -F
sudo iptables -t nat -F
sudo iptables -t nat -A POSTROUTING -o $eth -j MASQUERADE
sudo iptables -A FORWARD -i $eth -o $wlan -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i $wlan -o $eth -j ACCEPT
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo ifconfig $wlan $ip_address netmask $netmask
# Remove default route
sudo ip route del 0/0 dev $wlan &> /dev/null
sudo rm -rf /etc/dnsmasq.d/* &> /dev/null
echo -e "interface=$wlan \n\
bind-interfaces \n\
server=176.103.130.130 \n\
domain-needed \n\
bogus-priv \n\
dhcp-range=$dhcp_range_start,$dhcp_range_end,$dhcp_time" > /etc/dnsmasq.d/custom-dnsmasq.conf
sudo systemctl restart dnsmasq
echo -e "interface=$wlan\n\
driver=nl80211\n\
ssid=$ssid\n\
hw_mode=g\n\
ieee80211n=1\n\
wmm_enabled=1\n\
macaddr_acl=0\n\
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]\n\
channel=6\n\
auth_algs=1\n\
ignore_broadcast_ssid=0\n\
wpa=2\n\
wpa_key_mgmt=WPA-PSK\n\
wpa_passphrase=$psk\n\
rsn_pairwise=CCMP" > /etc/hostapd/hostapd.conf
sudo systemctl stop hostapd
sudo hostapd /etc/hostapd/hostapd.conf &