2

How can I check the GUI network setting is set DHCP or Static with command line? for the active and connected interface in Ubuntu 18.04

I want one line command like grep give me static/dhcp or true/false

screenshot

Fakhamatia
  • 1,202
  • 4
  • 13
  • 24

2 Answers2

3

Can use ip command to check interface you're interested in.

E.g. to check the interface eth0:

if ip -6 addr show eth0  | grep -q dynamic; then
    echo "Uses DHCP addressing"
else
    echo "Uses static addressing"
fi

-6 option is for checking IPv6 interface. You can use -4 for IPv4.

P.P
  • 117,907
  • 20
  • 175
  • 238
-1

nmcli -f ipv4.method con show

If the output is auto, then it is DHCP. If the output is manual, then it is static.

or

cat /etc/network/interfaces

DHCP enabled

auto eth0

iface eth0 inet dhcp

idan
  • 554
  • 6
  • 19