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 192.168.198.160 – the IP address of the interface.
  • netmask 255.255.255.0 – the subnet mask of the interface.
  • gateway 192.168.198.2 – 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