Unverified Commit 2cd59b4f authored by lanefu's avatar lanefu Committed by GitHub
Browse files

Merge pull request #143 from AristoChen/master

Allow user to specify DNS when setting static IP
parents 5859618e 34972630
...@@ -227,12 +227,13 @@ function create_if_config() { ...@@ -227,12 +227,13 @@ function create_if_config() {
address=$(ip -4 addr show dev $1 | awk '/inet/ {print $2}' | cut -d'/' -f1) 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) 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') gateway=$(route -n | grep 'UG[ \t]' | awk '{print $2}' | sed -n '1p')
dns=$gateway
echo -e "# armbian-config created" echo -e "# armbian-config created"
echo -e "source /etc/network/interfaces.d/*\n" echo -e "source /etc/network/interfaces.d/*\n"
if [[ "$3" == "fixed" ]]; then if [[ "$3" == "fixed" ]]; then
echo -e "# Local loopback\nauto lo\niface lo init loopback\n" echo -e "# Local loopback\nauto lo\niface lo init loopback\n"
echo -e "# Interface $2\nauto $2\nallow-hotplug $2" echo -e "# Interface $2\nauto $2\nallow-hotplug $2"
echo -e "iface $2 inet static\n\taddress $address\n\tnetmask $netmask\n\tgateway $gateway\n\tdns-nameservers 8.8.8.8" echo -e "iface $2 inet static\n\taddress $address\n\tnetmask $netmask\n\tgateway $gateway\n\tdns-nameservers $dns"
fi fi
} }
...@@ -351,15 +352,16 @@ function netmask_to_cidr () ...@@ -351,15 +352,16 @@ function netmask_to_cidr ()
# #
function nm_ip_editor () function nm_ip_editor ()
{ {
dns=$gateway
exec 3>&1 exec 3>&1
dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1 dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1 \n " 13 38 0 \
\n " 12 38 0 \ "Address:" 1 1 "$address" 1 15 15 0 \
"Address:" 1 1 "$address" 1 15 15 0 \ "Netmask:" 2 1 "$netmask" 2 15 15 0 \
"Netmask:" 2 1 "$netmask" 2 15 15 0 \ "Gateway:" 3 1 "$gateway" 3 15 15 0 \
"Gateway:" 3 1 "$gateway" 3 15 15 0 \ "DNS:" 4 1 "$dns" 4 15 15 0 \
2>&1 1>&3 | { 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 if [[ $? = 0 ]]; then
localuuid=$(LC_ALL=C nmcli -f UUID,DEVICE connection show | grep $1 | awk '{print $1}') localuuid=$(LC_ALL=C nmcli -f UUID,DEVICE connection show | grep $1 | awk '{print $1}')
# convert netmask value to CIDR if required # convert netmask value to CIDR if required
...@@ -372,14 +374,14 @@ exec 3>&1 ...@@ -372,14 +374,14 @@ exec 3>&1
# adjust existing # 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.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.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 nmcli con down $localuuid >/dev/null 2>&1
sleep 2 sleep 2
nmcli con up $localuuid >/dev/null 2>&1 nmcli con up $localuuid >/dev/null 2>&1
else else
# create new # 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 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 nmcli con up "armbian" >/dev/null 2>&1
fi fi
fi fi
...@@ -397,22 +399,22 @@ function systemd_ip_editor () ...@@ -397,22 +399,22 @@ function systemd_ip_editor ()
local filename="/etc/systemd/network/10-$1.network" local filename="/etc/systemd/network/10-$1.network"
if [[ -f $filename ]]; then if [[ -f $filename ]]; then
sed -i '/Network/,$d' $filename sed -i '/Network/,$d' $filename
exec 3>&1 exec 3>&1
dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1 dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1 \n " 13 38 0 \
\n " 12 38 0 \ "Address:" 1 1 "$address" 1 15 15 0 \
"Address:" 1 1 "$address" 1 15 15 0 \ "Netmask:" 2 1 "$netmask" 2 15 15 0 \
"Netmask:" 2 1 "$netmask" 2 15 15 0 \ "Gateway:" 3 1 "$gateway" 3 15 15 0 \
"Gateway:" 3 1 "$gateway" 3 15 15 0 \ "DNS:" 4 1 "$dns" 4 15 15 0 \
2>&1 1>&3 | { 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 if [[ $? = 0 ]]; then
echo -e "[Network]" >>$filename echo -e "[Network]" >>$filename
echo -e "Address=$address" >> $filename echo -e "Address=$address" >> $filename
echo -e "Gateway=$gateway" >> $filename echo -e "Gateway=$gateway" >> $filename
echo -e "DNS=8.8.8.8" >> $filename echo -e "DNS=$dns" >> $filename
fi fi
} }
fi fi
} }
...@@ -427,20 +429,20 @@ function ip_editor () ...@@ -427,20 +429,20 @@ function ip_editor ()
{ {
exec 3>&1 exec 3>&1
dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1 dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1 \n " 13 38 0 \
\n " 12 38 0 \ "Address:" 1 1 "$address" 1 15 15 0 \
"Address:" 1 1 "$address" 1 15 15 0 \ "Netmask:" 2 1 "$netmask" 2 15 15 0 \
"Netmask:" 2 1 "$netmask" 2 15 15 0 \ "Gateway:" 3 1 "$gateway" 3 15 15 0 \
"Gateway:" 3 1 "$gateway" 3 15 15 0 \ "DNS:" 4 1 "$dns" 4 15 15 0 \
2>&1 1>&3 | { 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 if [[ $? = 0 ]]; then
echo -e "# armbian-config created\nsource /etc/network/interfaces.d/*\n" >$3 echo -e "# armbian-config created\nsource /etc/network/interfaces.d/*\n" >$3
echo -e "# Local loopback\nauto lo\niface lo inet loopback\n" >> $3 echo -e "# Local loopback\nauto lo\niface lo inet loopback\n" >> $3
echo -e "# Interface $2\nauto $2\nallow-hotplug $2\niface $2 inet static\ echo -e "# Interface $2\nauto $2\nallow-hotplug $2\niface $2 inet static\
\n\taddress $address\n\tnetmask $netmask\n\tgateway $gateway\n\tdns-nameservers 8.8.8.8" >> $3 \n\taddress $address\n\tnetmask $netmask\n\tgateway $gateway\n\tdns-nameservers $dns" >> $3
fi fi
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment