Set a Static IP
This page will explain how to set a static IP in Linux.
-
Get the network adaptor
ip link
Find the adaptor named
ethx
,ensx
or something similar. -
Get IP and subnet mask (and more). Use the adaptor from the previous step, for example
eth0
.nmcli dev show eth0
ifconfig eth0
-
cd
into/etc/netplan
and runls
to see the config files.cd /etc/netplan ls
-
Open the file named
01-netcfg.yaml
(or something similar) using nano as root user:sudo nano 01-netcfg.yaml
01-netcfg.yml 1 2 3 4 5 6 7 8 9 10 11 12
network: version: 2 ethernets: eth0: dhcp4: no addresses: - 192.168.1.100/24 gateway4: 192.168.1.1 nameservers: addresses: - 8.8.8.8 - 1.1.1.1
- Change the address
192.168.1.100/24
to the desired IP. - Change
eth0
to the name of your network adaptor.
- Change the address
-
Apply the changes:
sudo netplan apply
-
Check if it worked:
ip addr show eth0