How do you set a static IP address in Ubuntu?

The steps to set a static IP address in Ubuntu are as follows:

  1. Open the terminal and enter the following command to open the network configuration file:
sudo nano /etc/netplan/01-netcfg.yaml
  1. Within the open document, locate the section regarding network interfaces, typically outlined in information such as the following:
network:
  version: 2
  ethernets:
    enp0s3:
      dhcp4: true
  1. Enable DHCP for IPv4.
  2. Do not use DHCP for IPv4.
network:
  version: 2
  ethernets:
    enp0s3:
      dhcp4: no
      addresses: [192.168.1.100/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
  1. Save changes and exit the editor (press Ctrl + X, then type Y to confirm saving, and finally press Enter to exit).
  2. To apply the new network configuration file, enter the following command:
sudo netplan apply
  1. To restart the network service, enter the following command:
sudo systemctl restart NetworkManager
  1. To check if the IP configuration is effective, enter the following command:
ip addr show enp0s3

By following the above steps, you will be able to successfully set a static IP address in Ubuntu.

bannerAds