Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
nspawn container change IP and use different CIDR than host
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
kgdrenefort
Guru
Guru


Joined: 19 Sep 2023
Posts: 312
Location: Somewhere in the 77

PostPosted: Sun Apr 07, 2024 11:47 am    Post subject: nspawn container change IP and use different CIDR than host Reply with quote

Hi,

I set up a binhost using nspawn.

From different starting of the nspawn container, the IP changes from the host, sometimes, sometimes it doesn’t.

This morning it has choose:
Code:
192.168.215.131/28


While I would like to keep the same IP as the host:
Code:
192.168.1.103/24


My first guess would be the way I start the container:

Code:
machinectl start lilithBinhost
machinectl login lilithBinhost


But, if I run:

Code:
systemd-nspawn -b -D /var/lib/machines/lilithBinhost/


It get the proper IP:
Code:
192.168.1.103/24


I guess both commands are not running the same way and doing the same thing. While using the last command I get a way more verbose output:

Code:
Spawning container lilithBinhost on /var/lib/machines/lilithBinhost.
Press Ctrl-] three times within 1s to kill container.
systemd 255 running in system mode (+PAM -AUDIT -SELINUX -APPARMOR +IMA +SMACK +SECCOMP +GCRYPT -GNUTLS +OPENSSL +ACL +BLKID -CURL -ELFUTILS -FIDO2 +IDN2 -IDN -IPTC +KMOD -LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY -P11KIT -QRENCODE -TPM2 -BZIP2 +LZ4 +XZ -ZLIB +ZSTD -BPF_FRAMEWORK -XKBCOMMON +UTMP -SYSVINIT default-hierarchy=unified)
Detected virtualization systemd-nspawn.
Detected architecture x86-64.

Welcome to Gentoo Linux!

Queued start job for default target Graphical Interface.
[  OK  ] Created slice Slice /system/getty.
[  OK  ] Created slice Slice /system/modprobe.
[  OK  ] Created slice User and Session Slice.
[  OK  ] Started Dispatch Password Req…ts to Console Directory Watch.
[  OK  ] Started Forward Password Requests to Wall Directory Watch.
[  OK  ] Reached target Path Units.
[  OK  ] Reached target Remote File Systems.
[  OK  ] Reached target Slice Units.
[  OK  ] Reached target Swaps.
[  OK  ] Listening on Process Core Dump Socket.
[  OK  ] Listening on Journal Socket (/dev/log).
[  OK  ] Listening on Journal Socket.
[  OK  ] Listening on User Database Manager Socket.
         Mounting Huge Pages File System...
         Mounting FUSE Control File System...
         Starting Journal Service...
         Starting Generate network units from Kernel command line...
         Starting Remount Root and Kernel File Systems...
         Starting Create Static Device Nodes in /dev gracefully...
[  OK  ] Mounted Huge Pages File System.
[  OK  ] Mounted FUSE Control File System.
[  OK  ] Finished Generate network units from Kernel command line.
[  OK  ] Reached target Preparation for Network.
[  OK  ] Finished Remount Root and Kernel File Systems.
[  OK  ] Started Journal Service.
         Starting Flush Journal to Persistent Storage...
         Starting User Database Manager...
[  OK  ] Started User Database Manager.
[  OK  ] Finished Flush Journal to Persistent Storage.
[  OK  ] Finished Create Static Device Nodes in /dev gracefully.
         Starting Create Static Device Nodes in /dev...
[  OK  ] Finished Create Static Device Nodes in /dev.
[  OK  ] Reached target Preparation for Local File Systems.
[  OK  ] Reached target Local File Systems.
[  OK  ] Reached target Containers.
[  OK  ] Listening on System Extension Image Management (Varlink).
         Starting Create Volatile Files and Directories...
[  OK  ] Finished Create Volatile Files and Directories.
         Starting Network Name Resolution...
[  OK  ] Reached target System Time Set.
         Starting Record System Boot/Shutdown in UTMP...
[  OK  ] Finished Record System Boot/Shutdown in UTMP.
[  OK  ] Started Network Name Resolution.
[  OK  ] Reached target Network.
[  OK  ] Reached target Host and Network Name Lookups.
[  OK  ] Reached target System Initialization.
[  OK  ] Started Daily Cleanup of Temporary Directories.
[  OK  ] Reached target Timer Units.
[  OK  ] Listening on D-Bus System Message Bus Socket.
[  OK  ] Reached target Socket Units.
[  OK  ] Reached target Basic System.
         Starting D-Bus System Message Bus...
         Starting Restore /run/initramfs on shutdown...
         Starting User Login Management...
         Starting Permit User Sessions...
[  OK  ] Finished Restore /run/initramfs on shutdown.
[  OK  ] Finished Permit User Sessions.
[  OK  ] Started Console Getty.
[  OK  ] Reached target Login Prompts.
[  OK  ] Started D-Bus System Message Bus.
[  OK  ] Started User Login Management.
[  OK  ] Reached target Multi-User System.
[  OK  ] Reached target Graphical Interface.


This is lilithBinhost (Linux x86_64 6.6.21-gentoo-dist) 13:36:35


I guess the easy way is simply to use the last command to start up my nspawn.

But I’m simply curious of these different behaviors.

By reading the options of systemd-nspawn, specially for the -b (--boot) option:

Code:
       -b, --boot
           Automatically search for an init program and invoke it as
           PID 1, instead of a shell or a user supplied program. If
           this option is used, arguments specified on the command
           line are used as arguments for the init program. This
           option may not be combined with --as-pid2.

           The following table explains the different modes of
           invocation and relationship to --as-pid2 (see above):

           Table 1. Invocation Mode
           ┌───────────────────────┬─────────────────────────┐
           │ Switch                │ Explanation             │
           ├───────────────────────┼─────────────────────────┤
           │ Neither --as-pid2 nor │ The passed parameters   │
           │ --boot specified      │ are interpreted as the  │
           │                       │ command line, which is  │
           │                       │ executed as PID 1 in    │
           │                       │ the container.          │
           ├───────────────────────┼─────────────────────────┤
           │ --as-pid2 specified   │ The passed parameters   │
           │                       │ are interpreted as the  │
           │                       │ command line, which is  │
           │                       │ executed as PID 2 in    │
           │                       │ the container. A stub   │
           │                       │ init process is run as  │
           │                       │ PID 1.                  │
           ├───────────────────────┼─────────────────────────┤
           │ --boot specified      │ An init program is      │
           │                       │ automatically searched  │
           │                       │ for and run as PID 1 in │
           │                       │ the container. The      │
           │                       │ passed parameters are   │
           │                       │ used as invocation      │
           │                       │ parameters for this     │
           │                       │ process.                │
           └───────────────────────┴─────────────────────────┘

           Note that --boot is the default mode of operation if the
           systemd-nspawn@.service template unit file is used.


If I get it, using -b will start all services as it was a «real» machine, and so, will probably start some networking tools, probably dhcpcd, and since the MAC address are identical from the host and the binhost:

Code:
70:85:c2:8d:11:c5


My networks will simply give it the same IP as host ?

Thanks for your time.

Regards,
GASPARD DE RENEFORT Kévin
_________________
Traduction wiki, pour praticiper.
Custom logos/biz card/website.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum