Reputation: 1402
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
Upvotes: 2
Views: 3133
Reputation: 121387
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.
Upvotes: 3
Reputation: 555
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
Upvotes: -1