<div dir="auto"><div dir="auto">There's no single service option to do this, as far as I know, since it involves a bit more than just making the interface visible.</div><div dir="auto"><br></div>After PrivateNetwork is enabled, the newly created namespaces need to be explicitly given network access through the host; the same "external" interface can't exist in two namespaces at once, so in Docker you usually have a virtual one.<div dir="auto"><br></div><div dir="auto">One method is a pair of 'veth' interfaces – one end stays in the host namespace, one is moved into the container namespace, and you have a virtual Ethernet cable between the two. The host end then usually goes into a bridge, and the host does routing and often NAT (just like it would for full VMs). Something needs to assign internal IP addresses to both interfaces, and something needs to add those NAT rules.</div><div dir="auto"><br></div><div dir="auto">(Another method is to create a 'macvlan' interface off the physical interface and give it to the container, which then gets its own IP address directly from the LAN.)</div><div dir="auto"><br></div><div dir="auto">It would be possible to do this with systemd services (maybe systemd-nspawn to set up namespaces plus networkd to configure the interfaces), but probably far more hacky than using a container runtime that does all such configuration by default.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 17, 2023, 22:04 Lucas Eduardo <<a href="mailto:lucas59356@gmail.com" rel="noreferrer noreferrer" target="_blank">lucas59356@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I am working on a service unit for a DHT crawler.<br>
<br>
For some reason, it doesn't work well with the default network settings<br>
because it seems to use a huge amount of traffic for a very small<br>
amount of findings.<br>
<br>
The same program works fine via docker, but I want to package it as a<br>
hardened systemd unit.<br>
<br>
A difference between the network layout in Docker and the host is that<br>
Docker only exposes the "lo" interface and an upstream one, and the host<br>
exposes everything and I think it's causing some kind of conflict.<br>
<br>
How can I implement this Docker behaviour in systemd?<br>
<br>
I tried using PrivateNetwork but it kills any Internet access because<br>
only localhost is available.<br>
<br>
Is there any not so well known feature to implement this?<br>
<br>
I am running systemd 251.7 on NixOS. I already have experience<br>
converting systemd stuff to the way the NixOS module system understands.<br>
<br>
Thanks in advance<br>
</blockquote></div>