When I type ifconfig, I see that my server has an new ip address each day. The ip addresses belong to a set of ip addresses.
How do I find out all the ip addresses of my server?

- 101
- 1
- 1
- 3
-
Do you mean ip addresses which could be designated to your server or ip addresses available on your server? – May 26 '09 at 19:04
7 Answers
Or
# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:0c:29:cc:ae:67 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.123/24 brd 192.168.0.255 scope global eth0
inet6 fe80::20c:29ff:fecc:ae67/64 scope link
valid_lft forever preferred_lft forever
-
1This is the correct solution, because it also shows the second, third (and so on) IP address which has been assigned to the *same* device using other methods than aliasing. – Binarus May 19 '20 at 16:07
I'm assuming you mean your server's IP address is assigned dynamically each day, and you want to know the pool of possible addresses your server can have. In that case, you can contact whoever is managing the DHCP server that assigns addresses in your network (or your ISP if the server is directly connected to the internet). If you want to know all the IPs your server has had int he past, you can put Lennart's answer in a cronjob.
ifconfig | grep inet | awk '{print $2}' >> .iplog
Or some such thing.
-
This fails if a device has been assigned multiple IP addresses (at least, when this has not been done by aliasing). – Binarus May 19 '20 at 16:08
Ask the people who adminster the dhcp server which assigns addresses to your server, it's the only way to know for sure.
You can relatively safely assume that your ipaddress always will be within ip-address binary-and netmask, there's however no guarantee of this behaviour, and chances are that the dhcp-servers address pool will be a subset of ipaddress & netmask.
Now, extrapolating, if you want to find out all the possible ip-addresses for your server because you want to be able to find it even after it has changed it's ip-address, I'd suggest checking out one of the dynamic dns providers on the internet.

- 5,994
- 1
- 27
- 20
A very simple way that prints all your IPv4 and IPv6 addresses:
ifconfig | grep inet | awk '{print $2}'
-
This fails if a device has been assigned multiple IP addresses (at least, when this has not been done by aliasing). – Binarus May 19 '20 at 16:05
running iproute2-5.9.0, ip -br a
is an easy way to list just interfaces, status, and ips. Here is how to gather only ipv4 addresses:
ip -br a | awk '{print$3}' | sed '/^$/d' | cut -f1 -d"/"

- 229
- 2
- 10
or:
#!/usr/bin/env bash
OS=`uname`
case $OS in
Linux) IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;
Darwin|FreeBSD|OpenBSD) IP=`ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;
SunOS) IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;
*) IP="Unknown";;
esac
echo "$IP"
found here.
-
This fails if a device has been assigned multiple IP addresses (at least, when this has not been done by aliasing). – Binarus May 19 '20 at 16:06
This will print all ip's except the 127.0.0.1 for localhost.
ifconfig | awk -F "[: ]+" '/inet addr:/ { if ($4 != "127.0.0.1") print $4 }'
-
This fails if a device has been assigned multiple IP addresses (at least, when this has not been done by aliasing). – Binarus May 19 '20 at 16:05