Login/Register

How to: Set a Static IP Address on Ubuntu and Debian via the Terminal

created by BasicSysAdmin

Tags: Ubuntu, Ubuntu 14.04, Ubuntu 15.04, Ubuntu 16.04, Debian, Debian 7

Jul 27, 2016

Introduction

This tutorial will cover the steps required to setup your Ubuntu or Debian machine with a static IP Address via the terminal.
https://www.youtube.com/watch?v=YPJPXDE93GM
Prerequisites

In order to follow this tutorial, you will need the following

  • Ubuntu or any other Debian based machine

  • Sudo Permissions


  • Changing your IP

    When using a server a server a lot it is always a good idea to give it a static IP address so we know where to look for it on another machine. We do this by editing our network config file by typing:

    sudo nano /etc/network/interfaces

    When you open this file, it should look like as follows:

    When you open this file, you will first need to delete the following lines:

    allow-hotplug eth0
    iface eth0 inet dhcp

    You will need to remove the two lines and replace with the following lines. (I will be adding my network configuration so
    auto eth0
    iface eth0 inet static
    address 10.0.0.150
    netmask 255.255.255.0
    gateway 10.0.0.1

    Once completed, it should look like this:

    make sure that the one you enter fits your network setup and that the information is available on your network). When you have done this, you will need to save the file (With Ctrl + O) and exit the file (With Ctrl + X)
    The next thing we need to do is set the DNS Servers. We do this by editing the following folder:
    sudo nano /etc/resolvconf/resolv.conf.d/base

    This file should be blank. You will need to add the following content.
    nameserver 8.8.8.8
    nameserver 8.8.4.4


    Now, I would recommend rebooting so that changes can be taken in to affect. When you log back in, you can run the following to view your network information.

    ifconfig