Score:0

Static wired LAN IP without a DHCP router ("Link-Local Only") on Ubuntu 20.04

cn flag

Disclaimer: I the noobest noob when it comes to networking. I hardly have an idea what means what in a network setup. For me, there is no "trivial" information in this regard.


I have an Ubuntu 20.04 machine and a Raspberry Pi, on my home wired LAN network. In the current setup, the only thing in between these devices is a network switch:

[ Ubuntu ] ——— [ network switch ] ——— [ RPi ]

I don't have a WAN internet connection on this network (and in the current setup I don't need one), as it is provided by another, a wifi interface. I use the wired LAN only to connect these devices.

Since there is no router on this LAN network to provide a DHCP config, in my network settings GUI, on the IPv4 tab, I set "Link-Local Only".

My Ubuntu can see the RPi, and the RPi can see my Ubuntu, but only on the condition that first I look up each device's own IP address with hostname -I, and then I use that IP address when connecting (mounting).

I have noticed that these IP addresses can change after reboots. They don't always do, and sometimes they return to previously used values, yet, in effect these changes roll an obstacle in the way of easy connecting. I'd like to set a static IP for both devices; I guess on this site I can ask about how to achieve it for my Ubuntu 20.04 machine.


I think that there may be a number of ways to achieve my goal, either through some config file, or the Settings GUI, or even by running some terminal commands (that I could put in a script).

Please, when suggesting a solution, take into account my lack of networking knowledge: I'm not after the industry best-practice — I prefer a method that's easier to carry out for a beginner.


Addendum:

  • I seem to be aware that on Ubuntu 20.04 netplan is often used in configuring networks; I have also seen renderer: NetworkManager in such configs.
    • Does this mean that I may have an option to avoid using netplan, and use something easier? (Netplan appears difficult as it seems to assume as a prerequisite a good level of networking knowledge.)
    • Would there be a way to override a netplan config with a terminal command "on the fly", comparable to how xrandr commands can "amend" X-server configs?
  • In the Network Settings GUI, on the IPv4 tab (where I choose "Link-Local Only"), there seems to be a Routes section, with Address, Netmask, Gateway, and Metric "fields", but these remain greyed out, even if I toggle the corresponding Automatic toggle to "off".
    • At the same time, the checkbox labelled Use this connection only for resources on its network also remains grayed out.

Update: solution summary

  • For this to work, one needs to set corresponding static IPs on all involved devices.
    • corresponding means: foo.bar.baz.x and foo.bar.baz.y
  • For the wired interface, one should choose an IP range different from that of the wifi interface's; e.g.:
    • wifi: foo.bar.x.x
    • wired: baz.quux.x.x
  • On Ubuntu, on the Network Settings GUI's IPv4 tab, one should choose "Manual", and proceed as per @raj's answer.
  • On a Raspberry Pi with Raspberry Pi OS based on Debian Buster, the /etc/dhcpcd.conf file needs to be modified: it already contains a helpful-enough "static IP example" snippet. More info on RPi.SE.
paladin avatar
kr flag
What is your questions/"goal"?
Levente avatar
cn flag
@paladin That when I run my mounting script, it can mount immediately, without the occasional bounce-back, where it says that the device is not accessible. A static IP would enable that smooth connecting every time, without having to muck with IP addresses.
Score:2
cn flag
raj

On desktop Ubuntu you don't have to use netplan, as there is Network Manager with a nice GUI to configure networking parameters.

Since you want a static IP, in the Network Settings GUI, in the IPv4 tab, set the "Method" to "Manual" and not "Link-local only". Choose an IP address for your Ubuntu machine. This address should belong to one of private address ranges: 10.x.x.x, 172.16.x.x or 192.168.x.x. It is most popular to use the third one :) Let's assume that the IP address will be for example 192.168.200.1 (take care that the range doesn't collide with your WiFi connection; if WiFi happens also to use 192.168.200.x, choose another range). Click "Add" and in the "Address" column enter that address. In the "Netmask" column, enter 255.255.255.0. As you don't have any router on this network, leave the "Gateway" column empty. Click "Save" and after you disconnect and re-connect your wired connection, your configured address should be set on the interface.

Of course you must also set another static IP address from the same range (for example 192.168.200.2) on your RPi, but I don't know what OS do you have there and can't provide you more detailed instructions.

Levente avatar
cn flag
Thank you, now `hostname -I` already returns the set value, now I quickly see if I can use it as intended from the Raspberry...
bac0n avatar
cn flag
note: 172.16.0.0/12 (172.16.x.x – 172.31.x.x)
Levente avatar
cn flag
So while I see the set IP in `hostname -I`, when I try to mount my Ubuntu shares on the RPi, I get "Connection timed out", and when I try to mount the Pi on the Ubuntu machine, I get "No route to host". (I have even restarted the network-switch.)
raj avatar
cn flag
raj
@bac0n I just wanted to describe things in a very simple way, so did not go into that :)
raj avatar
cn flag
raj
@Levente what IP your RPi has? You have to also set an address from 192.168.200.x on your RPi.
raj avatar
cn flag
raj
@Levente Both sides of the connection must have addresses from the same network, so both Ubuntu and RPi must be something from 192.168.200.x.
Levente avatar
cn flag
Ohhhh, so I need to set the Pi as well, within the same range! Thank you, I will look into that.
raj avatar
cn flag
raj
@Levente do not mix the address range from your WiFi connection with the wired one. You must keep it different.
Levente avatar
cn flag
Absolutely brilliant, both my mounting scripts work without a glitch on both Ubuntu and on the Pi. Thank you very much!
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.