Setting Up Network Interfaces in Linux

By | September 17, 2009

Ubuntu provides the following ways for setting the network interface:

  • During the installation process.  You will be asked to specify the settings for network devices found by system.
  • In the graphical interface of the system. Using the special user-friendly configurative utility. Given method is considered to be the easiest and most convenient one, especially for the beginners.
  • Using console utilities and direct editing of configurative files. This method should be used if there is no other opportunity (for example, for servers without graphical interface) or if you should define some specific parameters, which can be used by experienced network administrators.

Let’s try to configure your network card in Ubuntu (GNOME desktop environment). Here is the way it looks:

  1. System – Preferences – Network connections
  2. Now we can see all network connections that were automatically detected by OS.
  3. Choose a network connection in “Wired” section and press “Edit”
  4. 03 - Wired section (2)

  5. Enter your administrator password
  6. Choose “Ipv4 Settings” panel. In case there is DHCP server, choose “Automatic (DHCP)”, otherwise you need to manually introduce the above mentioned parameters – “Manual”option.
  7. 04 - IP4v Settings (2)

  8. As soon as you’re done, press “Apply” and restart. That’s it.

Let’s check what the procedure is if you would like to use text mode instead of graphical one.

The main command of interface configuration is ifconfig.

Entering ifconfig without any parameters will display active network interface, if you enter ifconfig-a, all the network interfaces will be displayed. To configure network interface you need to enter:

Ifconfig              interface            address               netmask             activation

For example:

Ifconfig                eth0                192.168.1.2         netmask              up

This means that we set 192.168.1.2 IP address to network interface and activated it (using up); in case you use down, you will deactivate given network interface.

Ifconfig is a very powerful command that has a lot of options for a delicate configuration of network interface (to learn more about it run man ifconfig command in the terminal).  At the same time usually there is no need to use this command. The reason for that consists in the fact that system will execute it by itself, taking all needed settings from configurative files. Thus it should be understood that ifconfig command just configures interfaces, but doesn’t save data.

All operating systems save such data in text files, but they do this in different ways:

  • In a text file all the parameters for ifconfig command are written in a single line. For instance, in the previous example it would look in the following way – ifconfig_eth0=”192.168.1.2 netmask 255.255.255.0″. Such a form of data saving is used in OS BSD.
  • In the text file the parameters are written separately, each under its name. This form is generally used for the majority of Linux distributions, including Ubuntu, so that’s why we will discuss in a while. It should be emphasized that the names of such a file are different depending on the distributions.
  • Parameters are written separately as well, but in this case for each interface a separate configurative file is created. Such a method is used in RedHat distributions (RedHat Linux, Fedora).

In case of Ubuntu you need to edit /etc/network/interfaces file by specifying all the necessary parameters. From all the above mentioned parameters of IP network, you need to enter everything, except DNS server address. Use any text editor and enter your settings after the line – iface eth0 inet static – as in following example:

auto lo eth0
iface lo inet loopback

iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1

05 - Interfaces file (2)

Save given file. After that use text editor again to enter your DNS server address in the file – /etc/resolv.conf – in a following way:

2 thoughts on “Setting Up Network Interfaces in Linux

  1. C H Tan

    hello vadim:
    this is an excellent work for beginners.

    I’m using Ubuntu 8.40. But the system-preferences do not give a link to network connections! so, I’m not getting the graphical interface that you have shown. Am I missing something?

    Could you kindly clarify?

    Thanks very much.

    1. Vladimir Usenco

      Could you, please, specify, what are you exactly getting?

Comments are closed.