[pve-devel] [PATCH container 7/9] configure static IP in LXC config for custom entrypoint
Filip Schauer
f.schauer at proxmox.com
Tue May 20 14:42:55 CEST 2025
When a container uses the default `/sbin/init` entrypoint, network
interface configuration is usually managed by processes within the
container. However, containers with a different entrypoint might not
have any internal network management process. Consequently, IP addresses
might not be assigned.
This change ensures that a static IP address is explicitly set in the
LXC config for the container.
Signed-off-by: Filip Schauer <f.schauer at proxmox.com>
---
src/PVE/LXC.pm | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index b2be27e..0131ac3 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -818,6 +818,18 @@ sub update_lxc_config {
if ($lxc_major >= 4) {
$raw .= "lxc.net.$ind.script.up = /usr/share/lxc/lxcnetaddbr\n";
}
+
+ if (!defined($d->{link_down}) || $d->{link_down} != 1
+ && PVE::LXC::Config->get_entrypoint($conf) ne "/sbin/init"
+ ) {
+ $raw .= "lxc.net.$ind.ipv4.address = $d->{ip}\n"
+ if defined($d->{ip}) && $d->{ip} !~ /^(dhcp|manual)$/;
+ $raw .= "lxc.net.$ind.ipv4.gateway = $d->{gw}\n" if defined($d->{gw});
+ $raw .= "lxc.net.$ind.ipv6.address = $d->{ip6}\n"
+ if defined($d->{ip6}) && $d->{ip6} !~ /^(auto|dhcp|manual)$/;
+ $raw .= "lxc.net.$ind.ipv6.gateway = $d->{gw6}\n" if defined($d->{gw6});
+ $raw .= "lxc.net.$ind.flags = up\n";
+ }
}
my $had_cpuset = 0;
--
2.39.5
More information about the pve-devel
mailing list