Setting up networking for an HVM

I’m installing a custom OS with HVM. The installation needs net connectivity. The docs just stops at how to figure out the IP, netmask, and gateway assigned to the HVM. How can I utilize this information to setup the network inside HVM? I only have commandline. I tried:

sudo ifconfig eth0 <ip> netmask 255.255.255.0 up
sudo ip route add default via <gateway-ip> dev eth0

Both command give no output. But if I do sudo ip route show default, it shows nothing. So probably the second command with ip route add isn’t working.

I can ping the gateway. But if I ping 8.8.8.8, it says “ping: connect: Network is unreachable”. What gives?

For context, I’m trying to install NixOS with its non-graphical installer. The installation needs to download from binary cache, that’s why it needs connectivity.

Works for me - what’s the output of ip a and route