Software >> OS >> Unix >> Linux >> Ubuntu >> How to configure static IP address

 

Ubuntu 20


## Ubuntu 20 uses netplan to manager network.  With 2 different possible backends
## (1) networkd  (2) NetworkManager
## main config file is in /etc/netplan/*.yaml
## Default install will use NetworkManager as the render and have the following

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

(command output)
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager


## Identity the interface names with

 

ip link show

(sample command output)
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:86:70:df brd ff:ff:ff:ff:ff:ff
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:ef:af:c2 brd ff:ff:ff:ff:ff:ff
4: enp0s9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:3e:c4:90 brd ff:ff:ff:ff:ff:ff



## in this example we have interfaces enp0s3, enp0s8, enp0s9

Using netplan


## create the netplan config file for networkd

sudo vi /etc/netplan/01-networkd-all.yaml


## Create the file as follows

/etc/netplan/01-networkd-all.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: true
    enp0s8:
      dhcp4: true
    enp0s9:
      addresses:
      - 192.168.0.107/24



## restart the network

sudo netplan apply


Using NetworkManager


## create the netplan config file for networkd

sudo vi /etc/netplan/01-NetworkManager-all.yaml


## Create the file as follows

/etc/netplan/01-NetworkManager-all.yaml
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp0s3:
      dhcp4: true
    enp0s8:
      dhcp4: true
    enp0s9:
      addresses:
      - 192.168.0.107/24



## restart the network

sudo netplan apply