Setup a static IP

List Attached Network Interfaces ip addr

caption

Setup a static IP

See also How exactly are NetworkManager, networkd, netplan, ifupdown2, and iproute2 interacting?

and Subnet Mask Cheat Sheet

Linux Mint

For a desktop, the best option is to configure it through the UI via NetworkManager.

Debian (linux cnc)

$ systemctl stop NetworkManager.service
$ systemctl disable NetworkManager.service
$ apt install resolvconf
# /etc/network/interfaces
# The primary network interface
allow-hotplug enp1s0
iface enp1s0 inet static
  address 192.168.0.135
  broadcast 192.168.0.255
  netmask 255.255.255.0
  gateway 192.168.0.254
  dns-nameservers 212.27.40.240
$ systemctl restart networking
$ systemctl restart resolvconf

Ubuntu 20.04 LTS / netplan.io

  • netplan creates configurations for either network manager before it starts. It is really a configuration abstraction and wheather it uses systemd-networkd or NetworkManager is part of the configuration.

Prefer NetworkManager for system with GUI, and networkd for headless server.

sudo nano /etc/netplan/2-netcfg.yaml

So far setting up a static ip with netplan with NetworkManager, prevent creation of interface for usb/ethernet adapter, unless explictly authorized in net plan config, for eg:

network:
  ethernets:
    # remarkable
    usb:
     match:
       name: enxa*
     dhcp4: yes

Ubuntu Server 18.04

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens160:
     dhcp4: no
     addresses: [192.168.1.137/24]
     gateway4: 192.168.1.254
     nameservers:
       addresses: [8.8.8.8,8.8.4.4]
ifo

Raspbian

Communicating with devices on a different subnet

Written on July 16, 2017, Last update on February 4, 2023
linux network system