0

I have a small router I am developing on Ubuntu 18.04 desktop and when I boot it without ethernet attached Netplan doesn't seem to assign the fixed IP (on the LAN side). WAN side is connected with DHCP. The LAN eth0 interface is what isc-dhcp-server runs on.

Problem : isc-dhcp-server crashes when it starts because no IP address exists on the eth0 interface.

If I do thinks manually with a device connected on eth0 then all works well. So the static IP is working when something is attached to eth0.

How do I get 192.168.10.1 assigned to eth0 (enp2s0 on this system) even if it's not plugged in?

I have a single .YAML file as follows:

# Let NetworkManager manage all devices on this system
network:
  ethernets:
    enp2s0:
      dhcp4: no
      addresses:
        - 192.168.10.1/24
      nameservers:
        addresses:
          - 8.8.8.8
          - 1.1.1.1
        search: []
    enp3s0:
      dhcp4: yes
  version: 2
 renderer: NetworkManager

Alternately - is there an easy way to just launch (or restart) isc-dhcp-server based on a trigger of the interface getting connected?

This was a very similar question below but it wasn't closed or validated from the OP ... and I haven't successfully found a way to accomplish this. Any help is appreciated.

Similar Question not Closed

Update 8/3/19: As noted above w.r.t. restarting the server, I found that the cable state can be found reliably at /sys/class/net/enp2s0/carrier -- the value in that file being 0 when disconnected and 1 when being connected.

So it seems then quite logical to have a script that would test this value - if the value is zero do nothing , if the value changes from 0 to 1 then execute a command , and finally if the value stays as 1 or changes from 1 to 0 do nothing. How would I write a bash script to accomplish this?

Update 8/14/19: Found a resolution following the answer below - but make sure you have ifupdown installed - my system did not. I did not pursue the script idea as the solution to get the static IP seems reliable.

  • 1
    Try adding optional: true to your eth0 stanza. Edit your question and show me your .yaml file. (And the question you link to, was answered, by me, but the original poster never showed up again.) – heynnema Aug 1 at 0:40
  • 1
    And... 192.168.10.1 may not be a good address choice, as it's possibly the same as the gateway address... similar problem in the other question. – heynnema Aug 1 at 0:47
  • 1
    optional: true is definitely the opposite of what you want in principle, because it means services should not wait for this interface to come up on boot before being started. – slangasek Aug 1 at 15:37
  • Agree @slangasek that 'optional: true' does not do what I want ; tried it for kicks but no change. The static IP is only assigned after I plug in a cable, but by that point the dhcp server has already exited with an error and stopped running. – user9974748 Aug 1 at 19:02
  • @heynnema Thanks for the tip, but there is no conflict with a local GW address – user9974748 Aug 2 at 0:03
0

For netplan, try this .yaml file...

network:
  version: 2
  renderer: networkd
  ethernets:
    enp2s0:
      addresses:
        - [192.168.10.1/24]
      gateway4: 
        - 192.168.xx.xx
      nameservers:
        addresses:
          - 8.8.8.8
          - 1.1.1.1
        search: []
    enp3s0:
      dhcp4: yes

sudo netplan --debug generate

sudo netplan apply

reboot

For NetworkManager, use this .yaml file...

network:
  version: 2
  renderer: NetworkManager

sudo netplan --debug generate

sudo netplan apply

and then edit /etc/network/interfaces to something similar to this...

auto lo
iface lo inet loopback

auto enp2s0
iface enp2s0 inet static
        address 192.168.10.1
        netmask 255.255.255.0
        gateway 192.168.xx.xx
        dns-nameservers 8.8.8.8 1.1.1.1

auto enp3s0
iface enp3s0 inet dhcp

reboot

Update #1:

  • decided to use NetworkManager

  • installed ifupdown

  • Thanks @heynnema , I plan to use NetworkManager on this system but when using netplan why also configure /etc/network/interfaces ? I thought that is ignored. I don't even think ifup or ifdown are installed but when I'm back at machine on Mon I will gave a try. – user9974748 Aug 4 at 19:15
  • @user9974748 report back on Mon, ok? For netplan, you don't use the /etc/network/interfaces file. But you mixed/matched stuff in your .yaml file. In desktop, if you leave /etc/network/interfaces with only the first two lines, you can use the GUI to do the same thing. Please remember to accept my answer if it turns out to be helpful, ok? Thanks! – heynnema Aug 4 at 19:17
  • I will definitely try on Mon @heynnema and will not to forget to mark answer if it solves problem ... but what is mixed in my YAML file? If the renderer is defined as NetworkManager and I define things in YAML I still don't understand the need for /etc/network/interfaces but I will experiment. Also pls remember that the interfaces and address all work when a cable is present - the issue is when no cable is present no IP is assigned to the interface card. It shows as "up" but doesn't have an IP. – user9974748 Aug 5 at 0:59
  • @user9974748 I think the thing to watch for is, after editing /etc/network/interfaces, and the .yaml, it'll use ifupdown to manage the ethernet hardware. That by itself may make isc-dhcp-server behave itself. As you say... play with it a little and see what happens, but try my way first, ok? Check out netplan.io/examples for NetworkManager examples. Report back. – heynnema Aug 5 at 1:06
  • When I define interfaces in /etc/network/interfaces they don't show up at all. I put them back in YAML and they showed up again. Maybe it's stating the obvious, but to be clear they show up with ifconfig and also with NetworkManager GUI on the desktop so they seem defined correct, just the static one doesn't get an IP w/o a cable attached. – user9974748 Aug 5 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.