freebsd
Goto Top

Linux Container ( LXC ) Netzwerkkonfiguration

Hallo,

ich versuche gerade auf eine aufgesetzte VM mit Debian Buster, Linux Container (lxc) einzusetzen. Ich habe aber ein Problem bei der Netzwerkkonfiguration und zwar hätte ich gerne die IPs via DHCP vergeben und diese auch ebenfalls von außen erreichen können. Ich habe aus dem Wikieintrag von Debian die Lösung mit "Host device as bridge" versucht zu verwenden, dabei bekomme ich aber nur eine ipv6 zugewiesen und keine ipv4.

Meine Konfiguration sieht wie folgt aus:

/etc/network/interfaces

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug enp0s3

iface enp0s3 inet dhcp

auto br0
iface br0 inet dhcp
        bridge_ports enp0s3
        bridge_fd 0
        bridge_maxwait 0
# This is an autoconfigured IPv6 interface
iface enp0s3 inet6 auto

und die Konfiguration des Containers:

lxc.net.0.type = veth
lxc.net.0.flags = up
lxc.net.0.link = br0
lxc.net.0.hwaddr = 00:FF:AA:00:00:01

lxc.apparmor.profile = generated
lxc.apparmor.allow_nesting = 1
lxc.rootfs.path = dir:/var/lib/lxc/dev/rootfs

# Common configuration
lxc.include = /usr/share/lxc/config/debian.common.conf

# Container specific configuration
lxc.tty.max = 4
lxc.uts.name = dev
lxc.arch = amd64
lxc.pty.max = 1024

Wie kann ich das Netzwerk des Containers so konfigurieren, dass dieser außerhalb der VM erreichbar ist und die ipv4 per DHCP vergeben wird?

Content-Key: 2983092589

Url: https://administrator.de/contentid/2983092589

Printed on: April 26, 2024 at 18:04 o'clock

Member: LordGurke
LordGurke Jun 03, 2022 at 23:26:43 (UTC)
Goto Top
Ist in dem Container denn ein DHCP-Client installiert und gestartet?
Standardmäßig wird nichts dergleichen geladen, es sei denn, du sagst es explizit - ein Interface auf DHCP zu konfigurieren reicht alleine nicht aus.
Du kannst ja mal im Container testweise "dhclient" ausführen und gucken, ob dann IP-Adressen zugewiesen werden.
Member: commodity
commodity Jun 04, 2022 updated at 07:26:59 (UTC)
Goto Top
Hallo,

ohne Linux-Basics geht es natürlich nicht. Wenn Du Copy/Paste machst (was absolut ok ist), dann folgende Empfehlung:
a) kopiere richtig
b) versuche zu verstehen, was Du da kopiert hast oder
c) lese es nach. Manpages, Linux Server Buch, Tutorials

Also, wenn Du nochmal auf Deine /etc/network/interfaces schaust:
Du definierst Deine Netzwerkverbindung mit iface enp0s3 inet6 auto

Wenn Du jetzt mal man interfaces eingibst, findest Du u.a. folgenden Text:

Stanzas  defining  logical  interfaces  start  with a line consisting of the word "iface" followed by the name of the logical interface.  In simple configurations without mapping stanzas this name should simply be the name of the physical interface to which it is to be applied.  (The default mapping script is, in effect, the echo command.)  The  interface name is followed by the name of the address family that the interface uses.  This will be "inet" for TCP/IP networking, but there is also some support for IPX networking ("ipx"), and IPv6 networking ("inet6").  Following that is the name of the method used to configure the interface.  

Auch im Debian-Wiki steht nichts von inet6 (und es wird auch empfohlen, das Interface von auto auf manual umzuschalten). Wenn Du eine Verbindung ausschließlich auf IPV6 definierst, wirst Du sie in Linux natürlich auch so bekommen. Nimm also mal die 6 weg, vielleicht klappt es dann schon. Sonst sehen wir weiter.

Wenn es das war, wäre es super, wenn Du in der Überschrift den Teil "Container (LXC)" rausnimmst. Dieser Fehler hat nämlich nichts mit Containern zu tun, sondern ist reine Linux basic Netzwerkkonfiguration.

Good Luck weiter!
Viele Grüße, commodity
Member: FreeBSD
FreeBSD Jun 04, 2022 at 12:13:00 (UTC)
Goto Top
Zitat von @commodity:

Hallo,

ohne Linux-Basics geht es natürlich nicht. Wenn Du Copy/Paste machst (was absolut ok ist), dann folgende Empfehlung:
a) kopiere richtig
b) versuche zu verstehen, was Du da kopiert hast oder
c) lese es nach. Manpages, Linux Server Buch, Tutorials

Also, wenn Du nochmal auf Deine /etc/network/interfaces schaust:
Du definierst Deine Netzwerkverbindung mit iface enp0s3 inet6 auto

Wenn Du jetzt mal man interfaces eingibst, findest Du u.a. folgenden Text:

Stanzas  defining  logical  interfaces  start  with a line consisting of the word "iface" followed by the name of the logical interface.  In simple configurations without mapping stanzas this name should simply be the name of the physical interface to which it is to be applied.  (The default mapping script is, in effect, the echo command.)  The  interface name is followed by the name of the address family that the interface uses.  This will be "inet" for TCP/IP networking, but there is also some support for IPX networking ("ipx"), and IPv6 networking ("inet6").  Following that is the name of the method used to configure the interface.  

Auch im Debian-Wiki steht nichts von inet6 (und es wird auch empfohlen, das Interface von auto auf manual umzuschalten). Wenn Du eine Verbindung ausschließlich auf IPV6 definierst, wirst Du sie in Linux natürlich auch so bekommen. Nimm also mal die 6 weg, vielleicht klappt es dann schon. Sonst sehen wir weiter.

Wenn es das war, wäre es super, wenn Du in der Überschrift den Teil "Container (LXC)" rausnimmst. Dieser Fehler hat nämlich nichts mit Containern zu tun, sondern ist reine Linux basic Netzwerkkonfiguration.

Good Luck weiter!
Viele Grüße, commodity

Servus,

danke für deine Antwort, leider hat das entfernen des ipv6 Interfaces nichts gebracht. Mein Container bekommt weiterhin eine ipv6 zugewisen, kann von außen nicht angesprochen werden und auch nicht nach außen kommnunizieren also außerhalb der VM.

/etc/network/interfaces

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#allow-hotplug enp0s3
#
#iface enp0s3 inet dhcp

auto br0
iface br0 inet dhcp
        bridge_ports enp0s3
        bridge_stp off
        bridge_fd 0
        bridge_maxwait 0

/var/lib/lxc/dev/config

# Template used to create this container: /usr/share/lxc/templates/lxc-debian
# Parameters passed to the template:
# Template script checksum (SHA-1): d5aa397522e36a17c64c014dd63c70d8607c9873
# For additional config options, please look at lxc.container.conf(5)

# Uncomment the following line to support nesting containers:
#lxc.include = /usr/share/lxc/config/nesting.conf
# (Be aware this has security implications)

lxc.net.0.type = veth
lxc.net.0.hwaddr = 00:16:3e:a1:77:ed
lxc.net.0.link = br0
lxc.net.0.flags = up
lxc.rootfs.path = dir:/var/lib/lxc/dev/rootfs

# Common configuration
lxc.include = /usr/share/lxc/config/debian.common.conf

# Container specific configuration
lxc.tty.max = 4
lxc.uts.name = dev
lxc.arch = amd64
lxc.pty.max = 1024

Ich habe ebenfalls versucht dem Container eine statische IP zuzuweisen aus dem Netzbereich, leider hat das nichts bewirkt.

Viele Grüße

FreeBSD
Member: commodity
commodity Jun 04, 2022 updated at 15:22:29 (UTC)
Goto Top
Sorry, ja, Du hattest auch in der ersten Konfig ja ein
iface enp0s3 inet dhcp
drin, das hatte ich übersehen und das hätte ausreichen sollen.

Bekommt denn der Rechner selbst (also die VM, die den Container beherbergt) eine IPV4-Adresse?
Und ist die network/interfaces die der VM oder des Hosts?
Poste mal bitte ip a (MAC-Adressen schwärzen). Am besten von Host und VM.

Viele Grüße, commodity
Member: commodity
commodity Jun 08, 2022 at 09:08:41 (UTC)
Goto Top
Und? Kommt hier noch was?

Viele Grüße, commodity