-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw2l-install.sh
executable file
·127 lines (109 loc) · 3.13 KB
/
w2l-install.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
#
# Site: www.hackhappy.org
# Article: http://hackhappy.org/uncategorized/how-to-use-a-raspberry-pi-to-create-a-wireless-to-wired-network-bridge/
# Video: http://youtu.be/FlLLmacDqJU
# Description: Shells script to configure linux to forward traffic
# from wireless to ethernet. This is useful if you do not have wire
# access to the router.
function Configure () {
clear
echo "############################################################"
echo "# Configure linux to connect wifi network to wired network #"
echo "############################################################"
echo ""
echo -n "Input LAN IP [192.168.0.1]: "
read lip
if [ "$lip" = "" ]; then
lip="192.168.0.1"
fi
echo -n "Input LAN Netmask [255.255.255.0]: "
read netmask
if [ "$netmask" = "" ]; then
netmask="255.255.255.0"
fi
echo -n "Input LAN Subnet [192.168.0.0]: "
read subnet
if [ "$subnet" = "" ]; then
subnet="192.168.0.0"
fi
echo -n "Input IP Range Start [192.168.0.2]: "
read ipstart
if [ "$ipstart" = "" ]; then
ipstart="192.168.0.2"
fi
echo -n "Input IP Range End [192.168.0.200]: "
read ipend
if [ "$ipend" = "" ]; then
ipend="192.168.0.200"
fi
echo -n "Input Wifi SSID: "
read ssid
echo -n "Input Wifi Password: "
read password
echo -n "Input LAN Device [eth0]: "
read landv
if [ "$land" = "" ]; then
land="eth0"
fi
echo -n "Input Wifi Device [wlan0]: "
read wifid
if [ "$wifid" = "" ]; then
wifid="wlan0"
fi
#Update system software
clear
echo ""
echo "##### Updating OS & Apps. This may take some time..."
echo ""
apt-get update
apt-get -y upgrade
#Configure devices
echo "
auto lo $land
iface lo inet loopback
iface $land inet static
address $lip
netmask $netmask
auto $wifid
iface $wifid inet dhcp
wpa-ssid \"$ssid\"
wpa-psk \"$password\"
up iptables-restore < /etc/iptables.ipv4.nat
" > /etc/network/interfaces
#install and configure the DHCP server
clear
echo "##### Installing and Configuring DHCP Server..."
echo "##### If you see any errors this is expected behaviour. Don't panic..."
echo ""
apt-get -y install isc-dhcp-server
echo "
option domain-name \"wifi2lan.rpi\";
option domain-name-servers 8.8.8.8, 8.8.4.4;
subnet $subnet netmask $netmask {
range $ipstart $ipend;
option routers $lip;
}
" > /etc/dhcp/dhcpd.conf
clear
echo "##### Restarting DHCP Server..."
echo ""
echo "INTERFACES=\"$land\"" > /etc/default/isc-dhcp-server
service isc-dhcp-server restart
update-rc.d isc-dhcp-server enable
#Install and configure iptables
clear
echo "##### Installing and Configuring IP Forwarding..."
echo ""
apt-get -y install iptables
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o $wifid -j MASQUERADE
iptables -A FORWARD -i $wifid -o $land -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $land -o $wifid -j ACCEPT
iptables-save > /etc/iptables.ipv4.nat
clear
echo "##### Installation Complete."
echo "##### Reboot or restart networking to apply new network configuration: sudo /etc/init.d/networking"
}
Configure