ethernet interface lost or couldn't find eth0

Problem

Turns out the root cause was no ifup or ifdown, which were both scripts required by /etc/init.d/networking to bring up networking

m@box:/etc/init.d$ ifup eth0
-bash: ifup: command not found
m@box:/etc/init.d$ ifdown eth0
-bash: ifdown: command not found

Nor I could find networking

m@box:/etc/init.d$ cat /etc/init.d/networking
cat: /etc/init.d/networking: No such file or directory

Also netplan is missing, but interfaces were replaced

m@box:/etc/init.d$ cat /etc/network/interfaces 
# ifupdown has been replaced by netplan(5) on this system.  See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
#    sudo apt install ifupdown

Solution

Temp fix to get back onto the internet to actually install networkd/netplan:

m@box:~$ ifconfig eth0 up
# xx.xx.xx.xx/24 is your static IP
m@box:~$ ip addr add xx.xx.xx.xx/24 dev eth0
# xx.xx.xx.1 is your gateway
m@box:~$ ip route add default via xx.xx.xx.1 dev eth0

long-term fix, install netplan, configure it to manage networkd:

m@box:~$ apt-get install netplan.io

We configure netplan(/etc/netplan/01-netcfg.yaml):

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      dhcp6: no
      addresses: [xx.xx.xx.xx/24]
      gateway4: xx.xx.xx.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
      match:
        macaddress: 00:00:00:00:00:00

To prevent "A start job is running for wait for network to be configured"

network:
  ethernets:
    eth0:
      optional: true

generate, try, apply and reboot

m@box:~$ netplan generate --debug
m@box:~$ netplan --debug generate
DEBUG:command generate: running ['/lib/netplan/generate']
** (generate:31842): DEBUG: 03:52:00.167: Processing input file /etc/netplan/01-netcfg.yaml..
** (generate:31842): DEBUG: 03:52:00.167: starting new processing pass
** (generate:31842): DEBUG: 03:52:00.167: Processing input file /etc/netplan/50-cloud-init.yaml..
** (generate:31842): DEBUG: 03:52:00.167: starting new processing pass
** (generate:31842): DEBUG: 03:52:00.168: We have some netdefs, pass them through a final round of validation
** (generate:31842): DEBUG: 03:52:00.168: eth0: setting default backend to 1
** (generate:31842): DEBUG: 03:52:00.168: Configuration is valid
** (generate:31842): DEBUG: 03:52:00.168: Generating output files..
** (generate:31842): DEBUG: 03:52:00.169: NetworkManager: definition eth0 is not for us (backend 1)
m@box:~$ netplan try
Do you want to keep these settings?


Press ENTER before the timeout to accept the new configuration


Changes will revert in 119 seconds
Configuration accepted.
m@box:~$ netplan apply
m@box:~$ reboot
Last modification:May 22, 2021
如果觉得我的文章对你有用,请随意赞赏