Making Local KVM Guests Accessible via Public IPv4 Addresses on Debian 12 Home Server
In this article, we will discuss how to make local KVM guests accessible via public IPv4 addresses on a Debian 12 (Bookworm) home server. This involves setting up a bridge network interface, configuring the KVM guests to use the bridge, and obtaining public IPv4 addresses for the guests.
Prerequisites
Before we begin, make sure you have the following:
- A physical Linux server with Debian 12 installed.
- Multiple KVM guests running on the server.
- Access to an IPv4 subnet and ASN (Autonomous System Number).
Setting Up the Bridge Network Interface
The first step is to set up a bridge network interface on the host server. This will allow the KVM guests to communicate with the outside world using the host server's network interface.
To create a bridge network interface, first install the bridge-utils package:
# apt-get update
# apt-get install bridge-utils
Next, create a new bridge interface called br0:
# nano /etc/network/interfaces
auto br0
iface br0 inet static
address
netmask
gateway
bridge_ports eth0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
Replace eth0 with the name of the network interface on your host server. Also, replace the IP address, netmask, and gateway with the appropriate values for your network.
After making these changes, restart the networking service:
# systemctl restart networking
Configuring the KVM Guests to Use the Bridge
Next, we need to configure the KVM guests to use the bridge network interface. This involves modifying the XML configuration file for each guest.
To modify the XML configuration file, first shut down the guest:
# virsh shutdown
Next, edit the XML configuration file:
# nano /etc/libvirt/qemu/.xml
Locate the <interface type='network'> section and modify it as follows:
<interface type='bridge'>
<mac address=''/>
<source bridge='br0'/>
<model type='virtio'/>
</interface>
Replace <mac address='<mac address>>'/> with the MAC address of the guest's network interface. Also, replace br0 with the name of the bridge network interface on the host server.
After making these changes, restart the libvirtd service:
# systemctl restart libvirtd
Finally, start up the guest:
# virsh start
Obtaining Public IPv4 Addresses for the Guests
The final step is to obtain public IPv4 addresses for the KVM guests. This involves contacting your Internet Service Provider (ISP) and requesting additional IPv4 addresses for your subnet and ASN.
Once you have obtained the public IPv4 addresses, configure them on the KVM guests by modifying the network configuration file for each guest. For example:
# nano /etc/network/interfaces
auto eth0
iface eth0 inet static
address
netmask
gateway
Replace eth0 with the name of the network interface on the guest. Also, replace the public IP address, netmask, and gateway with the appropriate values for your network.
In this article, we have discussed how to make local KVM guests accessible via public IPv4 addresses on a Debian 12 home server. This involves setting up a bridge network interface, configuring the KVM guests to use the bridge, and obtaining public IPv4 addresses for the guests. By following these steps, you can make your KVM guests accessible from anywhere on the Internet.