Static wired LAN IP without a DHCP router ("Link-Local Only") on Ubuntu 20.04
Andrew Mclaughlin
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
netplanis often used in configuring networks; I have also seenrenderer: NetworkManagerin 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
xrandrcommands can "amend" X-server configs?
- In the Network Settings GUI, on the
IPv4tab (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.xandfoo.bar.baz.y
- corresponding means:
- 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
- wifi:
- On Ubuntu, on the Network Settings GUI's
IPv4tab, 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.conffile needs to be modified: it already contains a helpful-enough "static IP example" snippet. More info on RPi.SE.
1 Answer
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.
9