How to find all IP address of a Linux server
To list all configured IP addresses on a server, you can use the command
1 |
hostname -I |
To find the main IP, use
1 |
hostname -I | awk '{print $1}' |
You can also use the command “ip addr” to list all IP address.
1 |
ip addr | grep "inet " |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
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 [~]# <pre> Another command that lists IP address is ifconfig <pre> root@server20 [~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 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<link> inet6 2607:5300:60:8248:: prefixlen 64 scopeid 0x0<global> 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<UP,BROADCAST,RUNNING,MULTICAST> 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<UP,BROADCAST,RUNNING,MULTICAST> 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<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> 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 [~]# |