tools: nm-in-vm: fix connectivity with host

The connectivity with the host depends on getting a DHCP lease from the
host. With the latest commit's customizations, the virtual NIC is not
managed by NM so it is not configured.

Keep it unmanaged so debuging NetworkManager doesn't affect to this
virtual NIC. Use dhclient to get a DHCP lease from the host. Assign a
fixed interface name (host_net) to match it from NM and dhclient config
files.
This commit is contained in:
Íñigo Huguet 2023-08-03 11:53:42 +02:00
parent db78d7b1b0
commit 2b44baf137
4 changed files with 28 additions and 1 deletions

View file

@ -13,3 +13,7 @@ managed=0
[device-managed-1]
match-device=interface-name:net*,interface-name:eth*
managed=1
[device-host-net]
match-device=interface-name:host_net
managed=0

View file

@ -0,0 +1,6 @@
[Match]
Driver=virtio_net
[Link]
NamePolicy=
Name=host_net

View file

@ -0,0 +1,14 @@
[Unit]
Description=dhclient service to get connectivity with the host
After=network.target
[Service]
Type=simple
Restart=on-failure
User=root
RestartSec=5
ExecStart=dhclient -d -H "%H" host_net
ExecStop=dhclient -r host_net
[Install]
WantedBy=multi-user.target

View file

@ -123,6 +123,8 @@ do_build() {
"home-gdbinit:/root/.gdbinit"
"home-gdb_history:/root/.gdb_history"
"home-behaverc:/root/.behaverc"
"systemd-10-host-net.link:/etc/systemd/network/10-host-net.link"
"systemd-dhcp-host.service:/etc/systemd/system/dhcp-host.service"
"systemd-20-nm.override:/etc/systemd/system/NetworkManager.service.d/20-nm.override"
)
@ -216,7 +218,8 @@ do_build() {
--edit "/etc/systemd/journald.conf:s/.*RateLimitBurst=.*/RateLimitBurst=0/" \
--delete "/etc/NetworkManager/system-connections/*" \
--append-line "/etc/bashrc:. /etc/bashrc.my" \
--run-command "updatedb"
--run-command "updatedb" \
--firstboot-command "systemctl enable --now dhcp-host"
virt-install \
--name "$VM" \