Score:0

Cannot setup static IP with Raspberry Pi on Ubuntu 20.04 Desktop

lk flag
jxw

I Ubuntu 20.04 Desktop OS running on Raspberry Pi 4. I have connected a printer to the Pi's ethernet port, and I have troubles in assigning a static IP using netplan. The problem is I cannot find the name of the interface card. Right now I have created a static IP using Network Manager and with the below command I can see that it is on eth0 with IP 192.168.123.101. The problem is I can't find the interface card name.

hd2900@hd2900:~$ ip add show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether e4:5f:01:49:85:7f brd ff:ff:ff:ff:ff:ff
    inet 192.168.123.101/24 brd 192.168.123.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether e4:5f:01:49:85:80 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.94/24 brd 192.168.1.255 scope global dynamic noprefixroute wlan0
       valid_lft 50472sec preferred_lft 50472sec
    inet6 fe80::5d0a:3259:a2fc:a0d4/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

In /etc/netplan/0-rpi-ethernet-eth0.yaml I have this content, and I suspect that driver bcmgenet smsc95xx and lan78xx is causing the problem.

hd2900@hd2900:/etc/netplan$ cat 10-rpi-ethernet-eth0.yaml 
    network:
      ethernets:
        eth0:
          # Rename the built-in ethernet device to "eth0"
          match:
            driver: bcmgenet smsc95xx lan78xx
          set-name: eth0
          dhcp4: true
          optional: true

To set up a static IP address I need to edit /etc/netplan/01-network-manager-all.yaml and I need to know the name of the network interface card.

hd2900@hd2900:/etc/netplan$ cat 01-network-manager-all.yaml 
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager 

As suggesteed by Simon Banks, I changed my file as below. However, I need to add a wifi connection.

network:
  version: 2
  renderer: networkd
  ethernets:
      eth0:
          dhcp4: false
          addresses: [192.168.123.101/24]
          gateway4: 192.168.123.1
          match:
              driver: bcmgenet smsc95xx lan78xx
          set-name: eth0

In order to add a wifi will below addition to the code work?

network:
  version: 2
  renderer: networkd
  ethernets:
      eth0:
          dhcp4: false
          addresses: [192.168.123.101/24]
          gateway4: 192.168.123.1
          match:
              driver: bcmgenet smsc95xx lan78xx
          set-name: eth0
  wifis:
      wlan0:
          dhcp4: true
          access-points: "SSID NAME"
          password: "password"
          

According to the suggests by Simon, I have changed the file /etc/netplan/01-network-manager-all.yaml to

cat /etc/netplan/01-network-manager-all.yaml

Let NetworkManager manage all devices on this system

network: version: 2 renderer: networkd ethernets: eth0: dhcp4: false addresses: [192.168.123.101/24] gateway4: 192.168.123.1 match: driver: bcmgenet smsc95xx lan78xx set-name: eth0 version: 2 wifis: wlan0: dhcp4: yes optional: true access-points: "HiddenDimsum2900_24Ghz": password: "mysecretPassword"

Hereafter I did sudo netplan --debug apply and got this output

sudo netplan --debug apply
** (generate:161651): DEBUG: 20:57:29.401: Processing input file /etc/netplan/01-network-manager-all.yaml..
** (generate:161651): DEBUG: 20:57:29.402: starting new processing pass

** (generate:161651): WARNING **: 20:57:29.402: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.
** (generate:161651): DEBUG: 20:57:29.402: wlan0: adding wifi AP 'HiddenDimsum2900_24Ghz'
** (generate:161651): DEBUG: 20:57:29.402: Processing input file /etc/netplan/10-rpi-ethernet-eth0.yaml..
** (generate:161651): DEBUG: 20:57:29.403: starting new processing pass
** (generate:161651): DEBUG: 20:57:29.403: We have some netdefs, pass them through a final round of validation
** (generate:161651): DEBUG: 20:57:29.403: wlan0: setting default backend to 1
** (generate:161651): DEBUG: 20:57:29.403: Configuration is valid
** (generate:161651): DEBUG: 20:57:29.403: eth0: setting default backend to 1
** (generate:161651): DEBUG: 20:57:29.403: Configuration is valid
** (generate:161651): DEBUG: 20:57:29.405: Generating output files..
** (generate:161651): DEBUG: 20:57:29.405: openvswitch: definition eth0 is not for us (backend 1)
** (generate:161651): DEBUG: 20:57:29.405: NetworkManager: definition eth0 is not for us (backend 1)
** (generate:161651): DEBUG: 20:57:29.405: Creating wpa_supplicant config
** (generate:161651): DEBUG: 20:57:29.406: wlan0: Creating wpa_supplicant configuration file run/netplan/wpa-wlan0.conf
** (generate:161651): DEBUG: 20:57:29.406: Creating wpa_supplicant unit /run/systemd/system/netplan-wpa-wlan0.service
** (generate:161651): DEBUG: 20:57:29.421: Creating wpa_supplicant service enablement link /run/systemd/system/systemd-networkd.service.wants/netplan-wpa-wlan0.service
** (generate:161651): DEBUG: 20:57:29.421: openvswitch: definition wlan0 is not for us (backend 1)
** (generate:161651): DEBUG: 20:57:29.421: NetworkManager: definition wlan0 is not for us (backend 1)
DEBUG:netplan generated networkd configuration changed, restarting networkd
DEBUG:eth0 not found in {}
DEBUG:wlan0 not found in {}
DEBUG:eth0 exists in {'eth0': {'dhcp4': False, 'addresses': ['192.168.123.101/24'], 'gateway4': '192.168.123.1', 'match': {'driver': 'bcmgenet smsc95xx lan78xx'}, 'set-name': 'eth0'}}
DEBUG:Merged config:
network:
  ethernets:
    eth0:
      addresses:
      - 192.168.123.101/24
      dhcp4: true
      gateway4: 192.168.123.1
      match:
        driver: bcmgenet smsc95xx lan78xx
      optional: true
      set-name: eth0
  renderer: networkd
  version: 2
  wifis:
    wlan0:
      access-points:
        HiddenDimsum2900_24Ghz:
          password: mySecretPassword
      dhcp4: true
      optional: true

DEBUG:netplan generated NM configuration changed, restarting NM
DEBUG:eth0 not found in {}
DEBUG:wlan0 not found in {}
DEBUG:eth0 exists in {'eth0': {'dhcp4': False, 'addresses': ['192.168.123.101/24'], 'gateway4': '192.168.123.1', 'match': {'driver': 'bcmgenet smsc95xx lan78xx'}, 'set-name': 'eth0'}}
DEBUG:Merged config:
network:
  ethernets:
    eth0:
      addresses:
      - 192.168.123.101/24
      dhcp4: true
      gateway4: 192.168.123.1
      match:
        driver: bcmgenet smsc95xx lan78xx
      optional: true
      set-name: eth0
  renderer: networkd
  version: 2
  wifis:
    wlan0:
      access-points:
        HiddenDimsum2900_24Ghz:
          password: mysecretPassword
      dhcp4: true
      optional: true

INFO:[]
WARNING:Cannot find unique matching interface for eth0: {'driver': 'bcmgenet smsc95xx lan78xx'}
DEBUG:Link changes: {}
DEBUG:netplan triggering .link rules for lo

From the output above I am wondering if the issue that I cannot connect to wlan0 is because wlan0 is not found in the first place?

When I do ip addr I got below output

ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether e4:5f:01:49:85:7f brd ff:ff:ff:ff:ff:ff
    inet 192.168.123.101/24 brd 192.168.123.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether e4:5f:01:49:85:80 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.94/24 brd 192.168.1.255 scope global dynamic noprefixroute wlan0
       valid_lft 51306sec preferred_lft 51306sec
    inet6 fe80::5d0a:3259:a2fc:a0d4/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

iwconfig yields this output

lo        no wireless extensions.

eth0      no wireless extensions.

wlan0     IEEE 802.11  ESSID:"HiddenDimsum2900_24Ghz"  
          Mode:Managed  Frequency:2.462 GHz  Access Point: 90:F8:91:3F:5F:5F   
          Bit Rate=72.2 Mb/s   Tx-Power=31 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:on
          Link Quality=64/70  Signal level=-46 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:93  Invalid misc:0   Missed beacon:0
ar flag
I think you are going about it the wrong way. You should set a static IP address for the printer (in the printer), not in Raspberry Pi. See [this answer](https://askubuntu.com/questions/1319320/connect-to-an-hp-printer-using-ethernet-cable/1319361#1319361) for a brief how to. The linked answer is for a laptop, but it should work for a Pi as well.
jxw avatar
lk flag
jxw
The printer part works fine now. It is the wifis part that does not work.
Score:0
in flag

I use netplan on my raspberry pi's via ubuntu and RPI OS.. Here is a direct cut and paste from my home servers netplan for its static configuration.. So just change the IP/Subnets to match your loca. Netplan does moan about not being able to match the drivers but it does seem to work so don't worry about them.

In order for this to work and not conflict with the broadband routers DHCP assignmentsI've configured it to not use the range 192.168.0.32-192.168.0.253 for DHCP.

network:
    version: 2
    renderer: networkd
    ethernets:
        eth0:
            dhcp4: false
            addresses: [192.168.0.10/24]
            gateway4: 192.168.0.254
            nameservers:
                addresses: [192.168.0.254]
            match:
                driver: bcmgenet smsc95xx lan78xx
            set-name: eth0
        wlan1:
            match:
                name: wlx0013eff402eb
            set-name: wlan1
    wifis:
        wlan0:
            dhcp4: yes
            optional: true
            access-points:
                RedactedEESID:
                    band: 5GHz
                    password: "REDACTED PASSWORD"
jxw avatar
lk flag
jxw
Thanks Simon. I tested it today and it works! Can you add to the script if I also want to connect to wifi using my wlan0? Basically there I need to connect to my router with ssid, password and dhcp4 is set to true. Should I add that under the ethernets section?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.