-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_router.sh
executable file
·67 lines (53 loc) · 1.83 KB
/
install_router.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
#!/bin/bash -e
# Script must be run as root
echo "Installing required packages dnsmasq hostapd iptables-persistent ..."
apt install -y dnsmasq hostapd iptables-persistent > /dev/null 2>&1
echo "Configuring /etc/network/interfaces ..."
cp /etc/network/interfaces /etc/network/interfaces.backup
if [ -e interfaces_router ]
then
cp interfaces_router /etc/network/interfaces
else
echo "Could not find file called interfaces_router"
exit 1
fi
echo "Configuring hostapd ..."
if [ -e hostapd_router ]
then
cp hostapd_router /etc/hostapd/hostapd.conf
else
echo "Could not find required file called hostapd_router"
exit 1
fi
echo "Configuring dnsmasq ..."
cp /etc/dnsmasq.conf /ect/dnsmasq.conf.backup
if [ -e dnsmasq_router ]
then
cp dnsmasq_router /etc/dnsmasq.conf
else
echo "Could not find required file called dnsmasq_router"
exit 1
fi
echo "Enabling ipv4 fowarding ..."
if [ -e /etc/sysctl.conf ]
then
echo "net.ipv4.ip_forward=1" > /etc/sysctl.conf
else
echo "Something went wrong /etc/sysctl.conf not found"
exit 1
fi
echo "Setting up iptables between wifi and ethernet network interfaces ..."
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE > /dev/null 2>&1
iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT > /dev/null 2>&1
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT > /dev/null 2>&1
iptables-save > /etc/iptables/rules.v4
echo "Stopping and disabling dhcpd.service ..."
systemctl stop dhcpcd.service > /dev/null 2>&1
systemctl disable dhcpcd.service > /dev/null 2>&1
echo "Starting and enabling dnsmasq.service ..."
systemctl start dnsmasq.service > /dev/null 2>&1
systemctl enable dnsmasq.service > /dev/null 2>&1
echo "Starting and enabling hostapd.service ..."
systemctl start hostapd.service > /dev/null 2>&1
systemctl enable hostapd.service > /dev/null 2>&1
exit 0