Setting a static IP Address and DNS Server in Ubuntu

Article was written using a Ubuntu server which is debian based. Other distros such as RedHat and SUSE may take different steps to configure networking.

If you require a static IP address for a Linux machine, you must configure a specific config file via the command line, there are GUI tools available which allow you to achieve this too.

So let’s start by first identifying the following:

  • IP Address for the machine
  • Netmask (AKA subnet mask)
  • Default Gateway
  • Broadcast Address
  • Network Address
  • Internal DNS Servers

To find your broadcast and network address use a subnet calculator

Once you have worked out the details above, you will then be ready to configure your machine. Please note it’s best to have physical access to the machine when doing the configuration, as doing so remotely can leave you disconnected permanently if you get something wrong.

Setting a static IP Address

We will do the configuration all from the command line (Terminal).

Identify the network interface you want to assign the IP Address to, to do this execute the following command:

ifconfig -a

You should see something similar to the image below:

image

As you can see this machine only has one physical interface, eth0 and one loopback. You will need to note down the interface name before continuing.

So let’s configure the interface, execute the following command:

sudo nano /etc/network/interfaces

You need to insert the details as shown in the screenshot below:

image

Once you have finished editing type Ctrl X and type Yes to save the configuration file. Even though we have edited the interface details it will not be live until we restart the networking services, which you can do via a reboot or by executing the following command:

sudo /etc/init.d/networking restart

You have now configured your linux machine with a static IP Address on interface eth0, but to confirm this has occurred execute the following command:

ifconfig

If you output as below you were successful:

image

You can also test connectivity by pinging your local gateway address.

ping 10.98.231.1 –c 4

Setting DNS Servers

DNS servers are required for name resolution.

So to start we will create a file called resolv.conf and will use google’s OpenDNS servers.

sudo nano /etc/resolv

Write the following into the config file:

image

Once you have edited type Ctrl X and type Yes to save the configuration file. You now have DNS resolution so pinging Google.com will work and so will normal web browsing.

Advertisements

1 thought on “Setting a static IP Address and DNS Server in Ubuntu”

  1. Thank you, I’ve recently been looking for info about this subject for a while and yours is the best I have found out till now. However, what about the conclusion? Are you sure about the source?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s