Configure a static IP address in Ubuntu

You can use the ifconfig command to configure the IP address in Ubuntu. However, the IP address configured this way is not permanent and will be lost after a reboot. If you want to set up a static IP address that will remain after the reboot, you will need to edit the /etc/network/interfaces file. Consider this example configuration:

etc network interfaces file

Here is a description of each line:

  • auto eth0 – the first Ethernet interface is usually identified as eth0.
  • iface eth0 inet static – defines that the static configuration will be used .
  • address – the IP address of the interface.
  • netmask – the subnet mask of the interface.
  • gateway – the IP address of the default gateway.

Save the changes and close the file. Run the sudo ifdown eth0 and sudo ifup eth0 commands to apply the changes. You can display your new settings using the ifconfig command:

ifconfig ubuntu

Geek University 2022