Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Config
Commits
2cd59b4f
Unverified
Commit
2cd59b4f
authored
May 05, 2021
by
lanefu
Committed by
GitHub
May 05, 2021
Browse files
Merge pull request #143 from AristoChen/master
Allow user to specify DNS when setting static IP
parents
5859618e
34972630
Changes
1
Show whitespace changes
Inline
Side-by-side
debian-config-functions-network
View file @
2cd59b4f
...
...
@@ -227,12 +227,13 @@ function create_if_config() {
address
=
$(
ip
-4
addr show dev
$1
|
awk
'/inet/ {print $2}'
|
cut
-d
'/'
-f1
)
netmask
=
$(
ip
-4
addr show dev
$1
|
awk
'/inet/ {print $2}'
|
cut
-d
'/'
-f2
)
gateway
=
$(
route
-n
|
grep
'UG[ \t]'
|
awk
'{print $2}'
|
sed
-n
'1p'
)
dns
=
$gateway
echo
-e
"# armbian-config created"
echo
-e
"source /etc/network/interfaces.d/*
\n
"
if
[[
"
$3
"
==
"fixed"
]]
;
then
echo
-e
"# Local loopback
\n
auto lo
\n
iface lo init loopback
\n
"
echo
-e
"# Interface
$2
\n
auto
$2
\n
allow-hotplug
$2
"
echo
-e
"iface
$2
inet static
\n\t
address
$address
\n\t
netmask
$netmask
\n\t
gateway
$gateway
\n\t
dns-nameservers
8.8.8.8
"
echo
-e
"iface
$2
inet static
\n\t
address
$address
\n\t
netmask
$netmask
\n\t
gateway
$gateway
\n\t
dns-nameservers
$dns
"
fi
}
...
...
@@ -351,15 +352,16 @@ function netmask_to_cidr ()
#
function
nm_ip_editor
()
{
dns
=
$gateway
exec
3>&1
dialog
--title
" Static IP configuration"
--backtitle
"
$BACKTITLE
"
--form
"
\n
Adapter:
$1
\n
"
12 38 0
\
exec
3>&1
dialog
--title
" Static IP configuration"
--backtitle
"
$BACKTITLE
"
--form
"
\n
Adapter:
$1
\n
"
13 38 0
\
"Address:"
1 1
"
$address
"
1 15 15 0
\
"Netmask:"
2 1
"
$netmask
"
2 15 15 0
\
"Gateway:"
3 1
"
$gateway
"
3 15 15 0
\
"DNS:"
4 1
"
$dns
"
4 15 15 0
\
2>&1 1>&3 |
{
read
-r
address
;
read
-r
netmask
;
read
-r
gateway
read
-r
address
;
read
-r
netmask
;
read
-r
gateway
;
read
-r
dns
if
[[
$?
=
0
]]
;
then
localuuid
=
$(
LC_ALL
=
C nmcli
-f
UUID,DEVICE connection show |
grep
$1
|
awk
'{print $1}'
)
# convert netmask value to CIDR if required
...
...
@@ -372,14 +374,14 @@ exec 3>&1
# adjust existing
nmcli con mod
$localuuid
ipv4.method manual ipv4.addresses
"
$address
/
$CIDR
"
>
/dev/null 2>&1
nmcli con mod
$localuuid
ipv4.method manual ipv4.gateway
"
$gateway
"
>
/dev/null 2>&1
nmcli con mod
$localuuid
ipv4.dns
"
8.8.8.8
,
$gateway
"
>
/dev/null 2>&1
nmcli con mod
$localuuid
ipv4.dns
"
$dns
,
$gateway
"
>
/dev/null 2>&1
nmcli con down
$localuuid
>
/dev/null 2>&1
sleep
2
nmcli con up
$localuuid
>
/dev/null 2>&1
else
# create new
nmcli con add con-name
"armbian"
ifname
"
$1
"
type
802-3-ethernet ip4
"
$address
/
$CIDR
"
gw4
"
$gateway
"
>
/dev/null 2>&1
nmcli con mod
"armbian"
ipv4.dns
"
8.8.8.8
,
$gateway
"
>
/dev/null 2>&1
nmcli con mod
"armbian"
ipv4.dns
"
$dns
,
$gateway
"
>
/dev/null 2>&1
nmcli con up
"armbian"
>
/dev/null 2>&1
fi
fi
...
...
@@ -399,18 +401,18 @@ function systemd_ip_editor ()
if
[[
-f
$filename
]]
;
then
sed
-i
'/Network/,$d'
$filename
exec
3>&1
dialog
--title
" Static IP configuration"
--backtitle
"
$BACKTITLE
"
--form
"
\n
Adapter:
$1
\n
"
12 38 0
\
dialog
--title
" Static IP configuration"
--backtitle
"
$BACKTITLE
"
--form
"
\n
Adapter:
$1
\n
"
13 38 0
\
"Address:"
1 1
"
$address
"
1 15 15 0
\
"Netmask:"
2 1
"
$netmask
"
2 15 15 0
\
"Gateway:"
3 1
"
$gateway
"
3 15 15 0
\
"DNS:"
4 1
"
$dns
"
4 15 15 0
\
2>&1 1>&3 |
{
read
-r
address
;
read
-r
netmask
;
read
-r
gateway
read
-r
address
;
read
-r
netmask
;
read
-r
gateway
;
read
-r
dns
;
if
[[
$?
=
0
]]
;
then
echo
-e
"[Network]"
>>
$filename
echo
-e
"Address=
$address
"
>>
$filename
echo
-e
"Gateway=
$gateway
"
>>
$filename
echo
-e
"DNS=
8.8.8.8
"
>>
$filename
echo
-e
"DNS=
$dns
"
>>
$filename
fi
}
fi
...
...
@@ -427,18 +429,18 @@ function ip_editor ()
{
exec
3>&1
dialog
--title
" Static IP configuration"
--backtitle
"
$BACKTITLE
"
--form
"
\n
Adapter:
$1
\n
"
12 38 0
\
dialog
--title
" Static IP configuration"
--backtitle
"
$BACKTITLE
"
--form
"
\n
Adapter:
$1
\n
"
13 38 0
\
"Address:"
1 1
"
$address
"
1 15 15 0
\
"Netmask:"
2 1
"
$netmask
"
2 15 15 0
\
"Gateway:"
3 1
"
$gateway
"
3 15 15 0
\
"DNS:"
4 1
"
$dns
"
4 15 15 0
\
2>&1 1>&3 |
{
read
-r
address
;
read
-r
netmask
;
read
-r
gateway
read
-r
address
;
read
-r
netmask
;
read
-r
gateway
;
read
-r
dns
;
if
[[
$?
=
0
]]
;
then
echo
-e
"# armbian-config created
\n
source /etc/network/interfaces.d/*
\n
"
>
$3
echo
-e
"# Local loopback
\n
auto lo
\n
iface lo inet loopback
\n
"
>>
$3
echo
-e
"# Interface
$2
\n
auto
$2
\n
allow-hotplug
$2
\n
iface
$2
inet static
\
\n\t
address
$address
\n\t
netmask
$netmask
\n\t
gateway
$gateway
\n\t
dns-nameservers
8.8.8.8
"
>>
$3
\n\t
address
$address
\n\t
netmask
$netmask
\n\t
gateway
$gateway
\n\t
dns-nameservers
$dns
"
>>
$3
fi
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment