System Administration

Network Configuration in Linux Terminal

24 Jul , 2014  

Networking is the basic thing to configure after installing a new operating system. Especially if you are a system administrator, in which case, almost never work on those computers directly. I only touch my computer hardware during OS installation, when network connection to the computer is lost or when I face hardware issue. Most of the time, management of those computers was done remotely. Therefore if you want to be able to manage it remotely, you must make sure those computers are configured to connect to the network and accessible from the network. I’ll show you how to configure networking using terminal in Debian/Ubuntu family of Linuxes.

The Network Configuration File

The networking in Debian/Ubuntu is managed by a network interface configuration file. In this file you will define each interface you want to use and the IP address for those interfaces. The file is /etc/network/interfaces, so open it with your favorite text editor.

vim /etc/network/interfaces

The Loopback Network Connection

Next we will talk about the content of this file. As I mentioned before, in here we will define network interfaces used by the computer. One interface that is always present in every computer to make a connection to itself (localhost) is the loopback connection. The configuration for loopback connection is basically the same on every computer, here is an example.

auto lo
iface lo inet loopback

What do those letters mean? In the first line, you define the name of the interface and whether you want your computer to load the interface automatically every time the system/network restart or not. Since I do, therefore I put auto lo which means I want to load interface lo to load automatically. In the second line, I defined the type of connection that I’m configuring. Since lo is a loopback connection, therefore I put loopback there.

The Ethernet Network Interface

Next interface to configure is the ethernet interface of your computer which you use to connect to the network using a LAN cable. In Linux, the interface is usually named as eth[n], with n is an increasing number of network card you have attached on the computer. For 2 network card, the interface name is usually eth0 and eth1. The configuration for ethernet can be divided to static or DHCP connection.

 

Configuration for computer with DHCP network

If you are in a network which has a DHCP service running, you can use this configuration for eth0.

auto eth0
iface eth0 inet dhcp

Now everythime you restart the system/networking, the configuration will use an IP based on the assignment from DHCP server.

 

Configuration for computer without DHCP network

If you don’t have a DHCP service running on your network, it means you have to allocate static IP manually to each computer. I assume you already know everything from IP address, netmask and gateway for your computer. Here is an example of static IP configuration for eth1.

auto eth1
iface eth1 inet static
address 192.168.1.13
netmask 255.255.255.0
gateway 192.168.1.1

Change the IP address, netmask and gateway IP with the one you use on your network.

Restart networking service

Now you’ve configured all interfaces, all you have to do is to restart the networking service so that the service will read the changes you’ve done on the configuration. The command to restart the service is.

service networking restart

or if you use older version of Debian/Ubuntu you can use

/etc/init.d/networking restart

And check if all of your interface is now running and having IP address by using this command.

ifconfig

If the IP is there, try to ping to the gateway IP. If you have a reply then congratulation, you are now connected to the network.

Here is the ubuntu manual page for /etc/network/interfaces for those of you who want to find out more about the configuration.

Satrio G. Nugraha

Satrio is a self-proclaimed technology geek. He is currently employed by IBM Indonesia as an IT Specialist which handles IBM xSeries servers, IBM zSeries mainframes and multi vendor network devices. He listens to various kinds of musics (he personally believes that music should not be put into boxes such as genres and everybody is free to listen to whatever kind of music whenever they feel like it).

Latest posts by Satrio G. Nugraha (see all)


Leave a Reply

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