I think the following works for operating systems that have netplan.

You can make a private IP that is static in 2 ways: from the router with an IP reservation or from the PC by configuring a netplan file.

For that you must enter

 /etc/netplan

then modify a file

The file must have the following content:

network:
version: 2
renderer: networkd
ethernets:
enp2s0:
dhcp4: false
addresses:
– 192.168.0.249/24
gateway4: 192.168.0.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4, 1.1.1.1]
optional: true

I write the same content in another format:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp2s0:
      dhcp4: false
      addresses:
        - 192.168.0.249/24
      gateway4: 192.168.0.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4, 1.1.1.1]
      optional: true

In that case I am choosing the static private IP 192.168.0.249

Detailed Explanation

  • network
    • This is the main block. All network code is placed within this block.
  • version: 2
    • Indicates that you are using version 2 of the Netplan syntax, which is the standard and current version.
  • renderer: networkd
    • Netplan does not manage the network directly, but rather generates configuration files for another service. networkd is the default network “engine” on Ubuntu Server and is the most recommended.
  • ethernets:
    • This block groups the configuration for all wired (Ethernet) network interfaces.
      • enp2s0:
        • This is the name of your network interface. It is crucial that you use the correct name for your system. You can verify this with the ip a command.
      • dhcp4: false
        • Tells the system not to attempt to obtain an IP address automatically via DHCP. When disabled, the system will use the static configuration you provide.
      • addresses:
        • A block where you define the static IP address(es) for the interface.
        • 192.168.0.249/24
          • Indicates that it’s a list item.
          • 192.168.0.249 is the IP address you assign to your server.
          • /24 is the CIDR notation for the subnet mask 255.255.255.0. This is the most modern and common way to specify it.
      • gateway4: 192.168.0.1
        • Specifies the IP address of the default gateway (the router). This is the address the server will use to send traffic to external networks, such as the internet. You should change this to the IP address of your router.
      • nameservers:
        • A block to define the DNS servers your server will use to resolve domain names (for example, to convert google.com to an IP address).
      • addresses: [8.8.8.8, 8.8.4.4, 1.1.1.1]
        • A list of DNS server IP addresses. Google and Cloudflare’s are used here. You can use your ISP’s if you prefer.
      • optional: true
        • Tells Netplan that the interface is optional. If the system cannot find this network interface at boot, it will continue the boot process without it, which can be useful on virtual servers or machines that sometimes boot without a network connection.

adjust the file permissions with the chmod command:

sudo chmod 600 /etc/netplan/01-netcfg.yaml

600 gives read and write permissions (6) only to the owner of the file, and no permissions (0) to anyone else.

Once you’ve made the changes, save the file and run:

sudo netplan apply

From Linux Ubuntu Server, check if the changes were applied, that is, your private IP:

hostname -I

The router has memory and shows the old IP, for that you must restart it

Restart the router and verify that it has chosen the new IP