Linux find DHCP server IP address using CLI

Linux find DHCP server IP address using CLI

To find the IP address of a Dynamic Host Configuration Protocol (DHCP) server on a Linux system using the command line, you can use the ip command. This command is used to configure network interfaces and display network information.

To find the IP address of the DHCP server, you can use the following command:

refe‮tual:ot r‬turi.com
ip addr show | grep 'inet .*global' | awk '{print $2}'

This command will list all network interfaces on the system (ip addr show), filter the output for lines with the string "inet" and "global" (grep 'inet .*global'), and then use the awk command to extract the second field of each line, which is the IP address (awk '{print $2}'). The IP address of the DHCP server should be the first address listed in the output.

Alternatively, you can use the ifconfig command to list the network interfaces and their IP addresses. To use ifconfig, you can run the following command:

ifconfig | grep 'inet addr:' | awk '{print $2}'

This command will list all network interfaces (ifconfig), filter the output for lines with the string "inet addr" (grep 'inet addr:'), and then use the awk command to extract the second field of each line, which is the IP address (awk '{print $2}'). The IP address of the DHCP server should be the first address listed in the output.

Created Time:2017-10-29 22:09:02  Author:lautturi