Set a Static IP
This page will explain how to set a static IP in Linux.
-
Get the network adaptor
ip linkFind the adaptor named
ethx,ensxor something similar. -
Get IP and subnet mask (and more). Use the adaptor from the previous step, for example
eth0.nmcli dev show eth0ifconfig eth0 -
cdinto/etc/netplanand runlsto 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.yaml01-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/24to the desired IP. - Change
eth0to the name of your network adaptor.
- Change the address
-
Apply the changes:
sudo netplan apply -
Check if it worked:
ip addr show eth0