I have a portabel device that sometimes needs connection to internet(to update) but will mostly be used directly connected to a laptop via ethernet cable. I want my users to have the plug and play benefits from dhcp ip when connected to a router but still be able to reach the device when no dhcp server is involved.

I basically want to do this but with systemd-networkd: auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp auto eth0:0 iface eth0:0 inet static address netmask

How do i achieve this with systemd-networkd and is there a better way to achieve same result?

  • 1
    That... really doesn't make sense. If you use a static address, then it's not plug&play anymore, since different LANs have different subnets and the static address wouldn't work in many of them. Commented Nov 27, 2015 at 11:06
  • I figured if the user is not using 192.128.0.x like most routers are configured. Then they probably also know how to find the dhcp ip thru the router. Once they have the ip they can connect to the device to change the static ip. The other reason i want a static ip is becaus i want the user to have the option to connect directly to a laptop with no dhcp server involved. Commented Nov 27, 2015 at 11:13
  • 2
    Could you try to clarify your question? What do you mean by "plug and play device", and is this the same device you want your users to connect to? Also, I don't understand what you mean when you say that you "don't want the users to connect.. without going through the hassle". So you want them to go through the hassle? In the end, I couldn't really figure out what it is you actually want to achieve (apart from the sentence that you wrote in the subject of your question).
    – vic
    Commented Nov 27, 2015 at 12:17
  • Is my question clear enough now? Commented Dec 2, 2015 at 16:25
  • I want something similar, but for a very different reason. I have an EC2 instance that has a secondary VIP assigned to it. It gets its primary IP from DHCP but I want to configure it to also be able to handle traffic it gets from the secondary ip. If I add the ip with ip addr add, then if systemd-networkd restarts I lose the secondary ip.
    – Thayne
    Commented Mar 24, 2021 at 18:06

2 Answers 2


I managed to make this work with the following configuration:





It is a little tricky as "ifconfig" does not show DHCP address for me, but if I look at journalctl or use "ip addr show" the DHCP address is there.

# ifconfig
eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::f0f7:36ff:fe00:1/64 Scope:Link
          RX packets:2721 errors:0 dropped:92 overruns:0 frame:0
          TX packets:947 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:218362 (213.2 KiB)  TX bytes:115488 (112.7 KiB)

lo        Link encap:Local Loopback  
          inet addr:  Mask:
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:5680 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5680 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:460080 (449.2 KiB)  TX bytes:460080 (449.2 KiB)


# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default 
    link/sit brd
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet brd scope global eth0
       valid_lft forever preferred_lft forever
    inet brd scope global dynamic eth0
       valid_lft 85430sec preferred_lft 85430sec
    inet6 fe80::f0f7:36ff:fe00:1/64 scope link 
       valid_lft forever preferred_lft forever
  • Thanks! Looks exactly like what I was looking for. Will try tomorrow and report my results. Commented Dec 2, 2015 at 18:43

You can configure dhclient.conf as follows:

timeout 10;

lease {
interface "eth0";
option subnet-mask;

interface "ep0" {
prepend domain-name-servers;

This will configure your dhcp to timeout after 10 seconds of not getting an IP address from a DHCP server and give the address on a /24 network. You can also set DNS servers in the configuration as well. Here's a link to the man page that I got this configuration from


  • 2
    User asked about systemd configuration explicit. Systemd does not use dhclient.
    – RDP
    Commented Dec 2, 2015 at 18:33

You must log in to answer this question.

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