-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure-dhcp
More file actions
executable file
·43 lines (36 loc) · 887 Bytes
/
Copy pathconfigure-dhcp
File metadata and controls
executable file
·43 lines (36 loc) · 887 Bytes
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
#!/bin/sh
set -e
if [ "$UID" -ne 0 ]; then
echo run as root
exit 1
fi
if [ "$#" -ne 1 ] && [ "$#" -ne 4 ] && [ "$#" -ne 5 ]; then
echo usage: configure-dhcp name [ ip default-gateway dns [ ip6 ] ]
exit 1
fi
NAME="$1"
sed -i '/'"$NAME"'/d' /etc/dhcpcd.conf
if [ "$#" -ne 1 ]; then
IP="$2"
GATEWAY="$3"
DNS="$4"
cat >> /etc/dhcpcd.conf <<EOF
# define static route $NAME
interface $NAME # $NAME
static ip_address=$IP # $NAME
EOF
IP6="$5"
if ! [ -z "$IP6" ]; then
grep 'ipv6ra_noautoconf' /etc/dhcpcd.conf >/dev/null \
|| echo 'ipv6ra_noautoconf' >> /etc/dhcpcd.conf
cat >> /etc/dhcpcd.conf <<EOF
static ip6_address=$IP6 # $NAME
EOF
fi
cat >> /etc/dhcpcd.conf <<EOF
static routers=$GATEWAY # $NAME
static domain_name_servers=$DNS # $NAME
EOF
fi
systemctl enable "dhcpcd@$NAME"
systemctl start "dhcpcd@$NAME"