Friday, February 12, 2016

Set a Static IP Address in Debian Based Linux

Out of the box, most systems seem to be configured to use DHCP to automatically obtain an IP address. For laptops/desktops, this is usually fine. For servers or any system that is going to accept incoming connections, setting a static IP address will make things easier. These instructions should apply to any Debian based Linux distribution, to include Ubuntu, Mint, Kali, etc.

The networking configuration is located at

Let's look at the default contents of the file
$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

Before changing the default configuration, make a copy just in case something gets messed up
$ sudo cp /etc/network/interfaces /etc/network/interfaces.bak

The part of the file that matter is the last line. I like to leave the old content there, commented out. The last line of the file looked like this
iface eth0 inet dhcp

And now I've updated that line and added some additional configuration so now it looks like this
#iface eth0 inet dhcp
iface eth0 inet static

You'll have to update those values based on your network setup. Now restart the networking daemon so the new settings take effect
$ sudo /etc/init.d/networking restart

Verify the new configuration using ifconfig
$ /sbin/ifconfig eth0

No comments:

Post a Comment