Cannot connect to the IPMI (iLO 4) from the same server

I have an HPE DL380e G8 server running Proxmox and I can't connect to iLO 4 neither from the web page nor from SSH when trying to connect from the same server (or when connecting from outside the network using a VPN tunnel hosted on the same machine).

I can connect to these without any problems from any other computer on the network but if I, for example, log in to a Proxmox VM and do ssh user@ilo-ip, I get this error:

ssh: connect to host ilo-ip port 22: No route to host

I can't even ping it:

PING ilo-ip (ilo-ip) 56(84) bytes of data.
From vm-ip icmp_seq=1 Destination Host Unreachable
...

iLO is like an additional little computer inside your server, it's called a Baseboard Management Controller (BMC for short).

iLO network connection can use a dedicated port (only BMC itself, nothing else) or be shared with the one of the server NICs.

If it's dedicated, you need an external switch to connect those interfaces.

If it's shared, the simple circuit just ensures there are no collisions, and nothing else. It is not nearly as advanced as, say, mini Ethernet switch. So there is nothing which could pass packets directly between iLO and NIC. If you connected that shared port to ordinary switch, it won't reflect packets back to the same port from which those originated, so it would be not possible to communicate either.

If the switch could configure a port to be a reflective relay port, it would be possible, because it then will reflect the packets back, but don't do this even if your switch supports that. This port mode is for very different purpose, and in this case you certainly have enough resources to dedicate some switch to connect iLO interfaces of your servers.

Better ask yourself, why do you need to communicate between the server and iLO over the Ethernet in the first place? They are already connected internally (IPMI SMBus interface). In Linux, you can use ipmiutil to access local IPMI BMC over SMBus, just ensure you've loaded the ipmi_devintf driver (module).

In general, if you don't have serious reasons to use shared mode (like that you install the server on the colocation where you pay per port), never use it. Always use the dedicated iLO port whenever possible.