To list all configured IP addresses on a server, you can use the command
hostname -I
To find the main IP, use
hostname -I | awk '{print $1}'
You can also use the command “ip addr” to list all IP address.
ip addr | grep "inet "
Example
root@server20 [~]# ip addr | grep "inet " inet 127.0.0.1/8 scope host lo inet 158.69.53.72/24 brd 158.69.53.255 scope global eth0 inet 158.69.114.170/32 brd 158.69.114.170 scope global eth0:cp1 inet 54.39.173.35/32 brd 54.39.173.35 scope global eth0:cp2 root@server20 [~]#Another command that lists IP address is ifconfigroot@server20 [~]# ifconfig eth0: flags=4163mtu 1500 inet 158.69.53.72 netmask 255.255.255.0 broadcast 158.69.53.255 inet6 fe80::ec4:7aff:fe69:9342 prefixlen 64 scopeid 0x20 inet6 2607:5300:60:8248:: prefixlen 64 scopeid 0x0 ether 0c:c4:7a:69:93:42 txqueuelen 1000 (Ethernet) RX packets 3423724119 bytes 670412248418 (624.3 GiB) RX errors 0 dropped 0 overruns 18691 frame 0 TX packets 3843828868 bytes 3897383743022 (3.5 TiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device memory 0xfb120000-fb13ffff eth0:cp1: flags=4163 mtu 1500 inet 158.69.114.170 netmask 255.255.255.255 broadcast 158.69.114.170 ether 0c:c4:7a:69:93:42 txqueuelen 1000 (Ethernet) device memory 0xfb120000-fb13ffff eth0:cp2: flags=4163 mtu 1500 inet 54.39.173.35 netmask 255.255.255.255 broadcast 54.39.173.35 ether 0c:c4:7a:69:93:42 txqueuelen 1000 (Ethernet) device memory 0xfb120000-fb13ffff lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 3364258789 bytes 4360941211553 (3.9 TiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3364258789 bytes 4360941211553 (3.9 TiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 root@server20 [~]#
Leave a Reply