I don't know which network manager Ubuntu uses, so I'm not sure whether this applies to you. I'm using Arch with the network manager systemd-networkd. I set it up manually from the CLI by creating a so called .network file in the /etc/systemd/network/ folder.
To "setup" and start using systemd-networkd, do sudo systemctl enable --now systemd-networkd.service. You will probably also need to setup systemd-resolved with sudo systemctl enable --now systemd-resolved.service because some services and/or programs need this for domain name resolution.
Then, check out point 3.5 on this page in the Arch Wiki: https://wiki.archlinux.org/title/Systemd-networkd
Use the section that applies to your setup depending on whether you are wired, wireless or both.
This of course assumes that Ubuntu doesn't use another network manager.