How do you set a static IP address in Ubuntu?
The steps to set a static IP address in Ubuntu are as follows:
- Open the terminal and enter the following command to open the network configuration file:
sudo nano /etc/netplan/01-netcfg.yaml
- 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
- Enable DHCP for IPv4.
- 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]
- Save changes and exit the editor (press Ctrl + X, then type Y to confirm saving, and finally press Enter to exit).
- To apply the new network configuration file, enter the following command:
sudo netplan apply
- To restart the network service, enter the following command:
sudo systemctl restart NetworkManager
- 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.