You are not logged in.

#1 2019-10-23 02:49:13

1ptb3b
Member
Registered: 2017-01-17
Posts: 76

Allow host to reach container with nspawn and Networkmanager [SOLVED]

Hello. I'm trying to get a simple container with nc to be able to reach the host machine. Here's what I tried.

### Creating the container

[host]# pacman -S arch-install-scripts
[host]# cd /var/lib/machines
[host]# mkdir mycontainer
[host]# pacstrap -c mycontainer base gnu-netcat
[host]# echo 'pts/0' >> mycontainer/etc/securetty
[host]# systemd-nspawn --network-veth --boot --directory mycontainer/

At the login screen, I login with `root` and no password.

### Configuring the container

[guest]# systemctl enable --now systemd-networkd
[guest]# systemctl enable --now systemd-resolved
[guest]# ln -f -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
[guest]# poweroff

I poweroff just in case. Not totally sure if that is necessary.

### Testing connectivity

[host]# systemd-nspawn --network-veth --boot --directory mycontainer/
[guest]# nc -l -p 6789
[host]# echo "hello" | nc localhost 6789

That `echo` I try from the host never seems to make it back to the container.

On the host, I'm neither using networkd nor resolved. I use NetworkManager because it integrates nicely with GNOME.

This is what my ip link looks like.

[host]$ ip link
18: ve-mycontainer@if2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether e2:b5:09:98:09:29 brd ff:ff:ff:ff:ff:ff link-netnsid 1

Is there a way to get NetworkManager to talk with the guest container? Ideally, I'd like the container to only talk with the host and not be able to talk with the internet.

Last edited by 1ptb3b (2019-10-23 21:35:21)

Offline

#2 2019-10-23 03:07:57

1ptb3b
Member
Registered: 2017-01-17
Posts: 76

Re: Allow host to reach container with nspawn and Networkmanager [SOLVED]

Oooh. Wait. Okay...

So `--network-veth` implies `--private-network`, huh.

When I removed that flag, then the host could reach the container...

Okay. Wait. So I guess solved? Sorry.

Offline

Board footer

Powered by FluxBB