3

I'm trying to setup container that has access to the internet but have been unsuccessful so far.

# sudo systemd-nspawn -nb -M debian-tree
# systemctl enable --now systemd-networkd systemd-resolved
# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: host0@if8: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state LOWERLAYERDOWN mode DEFAULT group default qlen 1000
    link/ether 42:ca:d5:8c:af:60 brd ff:ff:ff:ff:ff:ff link-netnsid 0
# ping google.com
ping: google.com: Temporary failure in name resolution

On the host

# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: wlp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
    link/ether 7c:7a:91:ae:7d:47 brd ff:ff:ff:ff:ff:ff
8: ve-debian-tree@if2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 92:f7:e1:4b:c6:6f brd ff:ff:ff:ff:ff:ff link-netnsid 0

Any ideas why it's not working?

2
  • In my experience, you need to enable systemd-networkd before booting (which should only need to be done once). Then again, I think I tried to get networking working in a Debian container, but didn't get it, though it did work in Ubuntu 17.10 Artful.
    – jpkotta
    Commented Aug 28, 2018 at 22:39
  • any updates during 2021?
    – rho
    Commented Oct 7, 2021 at 16:33

2 Answers 2

0

In my experience, both container and host are needed to be running systemd-networkd and systemd-resolved. It works in Ubuntu Bionic but not Xenial, because latter is using /etc/network/interfaces (networking.service) instead of systemd-networkd.

It also does not work on Debian stretch for the same reason.

0

Your problem is you probably not having DNS resolver properly setup.

By inspoecting you output, we indeed see that container has it's own network namespace (networking stack) attached and this stack disconnected from the main machine, and that you have virtual network cable host0@if8 going into the main machine link-netnsid 0 (netns 0 = host networking stack):

2: host0@if8: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state LOWERLAYERDOWN mode DEFAULT group default qlen 1000
    link/ether 42:ca:d5:8c:af:60 brd ff:ff:ff:ff:ff:ff link-netnsid 0

We also see that other part of this virtual network cable is stuck into main host networking namespace (primary networking stack):

8: ve-debian-tree@if2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 92:f7:e1:4b:c6:6f brd ff:ff:ff:ff:ff:ff link-netnsid 0

I am not entirely sure, but state on the host should be state UP and not state DOWN as it is reported.

Anyway, you should get ip addresses of the given links with ip addr and you should be able to ping respective interfaces (both local one and host one) from within the container.

Once this works - you should be able to ping an interface where your DNS server is running. If this DNS server is unreachable you need to fix it.

Once you get that going you should be able to resolve external DNS names.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .