How to set a static IP address in Linux via command line

To set a static IP address in Linux, simple edit /etc/network/interfaces and change your interface settings using the example below:

In this example, I’m setting my IP address to 192.168.1.100.

# The primary network interface
auto eth0
iface eth0 inet static
  address 192.168.1.100
  netmask 255.255.255.0
  network 192.168.1.0
  broadcast 192.168.1.255
  gateway 192.168.1.1

If you’re using Ubuntu and you want to set static nameservers, see this article: The Correct Way to Set Nameservers in Ubuntu 12.04 and up

This entry was posted in Linux and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *