-
Notifications
You must be signed in to change notification settings - Fork 1
/
netplan-easy.sh
165 lines (128 loc) · 4.87 KB
/
netplan-easy.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#########################################################################
# #
# Name of Script: netplan-easy #
# Description: no comment #
# Author: Jose Manuel Afonso Santana #
# Alias: joseafon #
# Email: jmasantana@linuxmail.org #
# #
#########################################################################
#!/bin/sh
clear
# CONS
NICKNAME=$(ip address show | grep -w 2 | awk '{print $2}')
if [ $USER != 'root' ]
then
echo "\e[31mYou need privileges of administrator\e[0m"
echo
exit 1
fi
which apt > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "\e[31mYour operating system is not compatible with this script\e[0m"
echo
exit 2
fi
if [ ! -d /etc/netplan/original ]
then
mkdir -p /etc/netplan/original
mv /etc/netplan/*.yaml /etc/netplan/original || mv /etc/netplan/*.yml /etc/netplan/original
fi
echo "\e[92m
███╗ ██╗███████╗████████╗██████╗ ██╗ █████╗ ███╗ ██╗
████╗ ██║██╔════╝╚══██╔══╝██╔══██╗██║ ██╔══██╗████╗ ██║
██╔██╗ ██║█████╗ ██║ ██████╔╝██║ ███████║██╔██╗ ██║
██║╚██╗██║██╔══╝ ██║ ██╔═══╝ ██║ ██╔══██║██║╚██╗██║
██║ ╚████║███████╗ ██║ ██║ ███████╗██║ ██║██║ ╚████║
╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═══╝
███████╗ █████╗ ███████╗██╗ ██╗
██╔════╝██╔══██╗██╔════╝╚██╗ ██╔╝
█████╗ ███████║███████╗ ╚████╔╝
██╔══╝ ██╔══██║╚════██║ ╚██╔╝
███████╗██║ ██║███████║ ██║
╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝
\e[0m"
echo "\e[96m
+---------------------------------+
| Input IP address |
+---------------------------------+
\e[0m"
echo
read IP
echo "\e[96m
+---------------------------------+
| Input CIDR prefix |
+---------------------------------+
\e[0m"
echo
echo "\e[92mExamples\e[0m"
echo "--------------------"
echo "\e[96m24 =\e[0m \e[93m255.255.255.0\e[0m"
echo "\e[96m16 =\e[0m \e[93m255.255.0.0\e[0m"
echo "\e[96m8 = \e[0m\e[93m255.0.0.0\e[0m"
echo "---------------------"
echo
read CIDR
if [ $CIDR -gt 32 -o $CIDR -lt 0 ]
then
echo
echo "\e[31mPrefix out of range\e[0m"
echo
exit 3
fi
echo "\e[96m
+---------------------------------+
| Input Gateway |
+---------------------------------+
\e[0m"
read GATEWAY
echo "\e[96m
+---------------------------------+
| Input DNS 1 |
+---------------------------------+
\e[0m"
read DNS1
echo "\e[96m
+---------------------------------+
| Input DNS 2 |
+---------------------------------+
\e[0m"
read DNS2
echo "
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
$NICKNAME
dhcp4: no
dhcp6: no
addresses: [$IP/$CIDR]
gateway4: $GATEWAY
nameservers:
addresses: [$DNS1,$DNS2]" > /etc/netplan/01-netcfg.yaml
echo
echo "\e[96mchecking file syntax\e[0m"
netplan --debug generate > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo
echo "\e[31mError of sintax\e[0m"
echo
exit 4
else
echo
netplan apply
echo "\e[92mDone\e[0m"
fi
echo
echo "\e[96mChecking internet connection\e[0m"
echo
ping -c 4 8.8.8.8
sleep 2
clear
echo "\e[92mAll Done\e[0m"
echo
networkctl status