Score:0

Assigning a fixed IP to a VM on Alma Linux

fi flag

I have a Alma Linux 9 host with two IP addresses.

I want assign one IP to the host (This is already done) and the second one to a Ubuntu VM.

What's the best way to do this? I've set up the VM through Cockpit, and it got an internal IP address.

I tried this to add Masquerading so the traffic for the ports I need is forwarded:

sudo firewall-cmd --permanent --new-policy VMForwardPolicy
sudo firewall-cmd --permanent --policy=VMForwardPolicy --add-ingress-zone=HOST
sudo firewall-cmd --permanent --policy=VMForwardPolicy --add-egress-zone=ANY
sudo firewall-cmd --permanent --policy=VMForwardPolicy --add-rich-rule='rule family="ipv4" destination address="<public-ip>" forward-port port="22" protocol="tcp" to-port="22" to-addr="192.168.122.134"'
sudo firewall-cmd --permanent --policy=VMForwardPolicy --add-rich-rule='rule family="ipv4" destination address="<public-ip>" forward-port port="443" protocol="tcp" to-port="443" to-addr="192.168.122.134"'
sudo firewall-cmd --permanent --policy=VMForwardPolicy --add-rich-rule='rule family="ipv4" destination address="<public-ip>" forward-port port="443" protocol="udp" to-port="443" to-addr="192.168.122.134"'
sudo firewall-cmd --reload

This worked, but only gave me internal access from the host to the public IP, any traffic from outside would not work.

When I changed the ingress zone to "ANY", I could no longer reach the IP at all.

I'd also prefer to forward any traffic and not just certain ports.

I'm not familiar with networking, so any help would be appreciated. I don't think firewall-cmd is the best way to do this, but I got further with it than with iptables or nftables.

pt flag
Does this answer your question? [Can I have my KVM guests on the same subnet as the host?](https://serverfault.com/questions/1075408/can-i-have-my-kvm-guests-on-the-same-subnet-as-the-host)
Aaron Dewes avatar
fi flag
@larsks Thanks for the reply, but trying this caused my server to be completely unreachable trough the network...
pt flag
That sounds like an error in the procedure. When making those sorts of changes you do want to ensure you have out-of-band access to your server -- either via another network interface, a serial console, or the actual screen/keyboard.
Aaron Dewes avatar
fi flag
Yes, I do have physical access, but I still couldn't figure out the issue.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.