How to get ip address of a server on Centos 7 in bash

You can use hostname command :

ipaddr=$(hostname -I)

-i, --ip-address:
Display the IP address(es) of the host. Note that this works only if the host name can be resolved.

-I, --all-ip-addresses:
Display all network addresses of the host. This option enumerates all configured addresses on all network interfaces. The loopback interface and IPv6 link-local addresses are omitted. Contrary to option -i, this option does not depend on name resolution. Do not make any assumptions about the order of the output.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)