-
Notifications
You must be signed in to change notification settings - Fork 6
/
static_ip.sh
executable file
·54 lines (47 loc) · 2.11 KB
/
static_ip.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
#!/bin/bash
NETWORK=/etc/network/interfaces
if [ $1 = "on" ]; then
echo "Turning On - Static IP"
echo "# interfaces(5) file used by ifup(8) and ifdown(8)" > "${NETWORK}"
echo "# Include files from /etc/network/interfaces.d:" >> "${NETWORK}"
echo "source-directory /etc/network/interface" >> "${NETWORK}"
echo "" >> "${NETWORK}"
echo "# Set static ip on ethernet interface of 192.168.1.139" >> "${NETWORK}"
echo "allow-hotplug eth0" >> "${NETWORK}"
echo "iface eth0 inet static" >> "${NETWORK}"
echo " address 192.168.1.139" >> "${NETWORK}"
echo " netmask 255.255.255.0" >> "${NETWORK}"
echo " gateway 192.168.0.1" >> "${NETWORK}"
echo " dns-nameservers 4.4.4.4" >> "${NETWORK}"
echo " dns-nameservers 8.8.8.8" >> "${NETWORK}"
echo "" >> "${NETWORK}"
echo "Static IP has been turned ON"
elif [ $1 = "off" ]; then
echo "Turning Off - Static IP"
echo "# interfaces(5) file used by ifup(8) and ifdown(8)" > "${NETWORK}"
echo "# Include files from /etc/network/interfaces.d:" >> "${NETWORK}"
echo "source-directory /etc/network/interface" >> "${NETWORK}"
echo "" >> "${NETWORK}"
echo "# Set static ip on ethernet interface of 192.168.1.139" >> "${NETWORK}"
echo "#allow-hotplug eth0" >> "${NETWORK}"
echo "#iface eth0 inet static" >> "${NETWORK}"
echo "# address 192.168.1.139" >> "${NETWORK}"
echo "# netmask 255.255.255.0" >> "${NETWORK}"
echo "# gateway 192.168.0.1" >> "${NETWORK}"
echo "# dns-nameservers 4.4.4.4" >> "${NETWORK}"
echo "# dns-nameservers 8.8.8.8" >> "${NETWORK}"
echo "" >> "${NETWORK}"
echo "Static IP has been turned OFF"
echo "Make sure to disconnect from the network before trying to reach the internet!"
fi
if [ $1 = "on" ] || [ $1 = "off" ]; then
echo "Restarting network-manager"
service network-manager restart
echo "Restarting networking"
service networking restart
echo "Restart Complete"
else
echo "Error: Static Preference not given"
echo "Example On: sudo ./static_ip.sh on"
echo "Example Off: sudo ./static_ip.sh off"
fi