Perhaps the most important thing in today's desktop computer is the network connection. Setting your network connection involves mainly setting the interface you use for connecting to the network. When it comes to setting a network interface, the ifconfig command is the godfather of all the commands.
For most popular distros, you have graphical tools for setting the Ethernet interface, even at the installation stage. There are many various tools for configuring the interface in the desktop environment, but I think that being able to configure it from a command line is an important and very simple task.
To start with, we should check what we are working with. This is done by entering the command "ifconfig -a" in the command line. The "-a" argument is useful for displaying the status of all the interfaces, even for those that are down. Now, you should be able to see your interface there. If there is a standard network card, it will have the name eth0. If you have more than one Ethernet card, there will be more eth adapters. The first one is eth0, the second is eth1 and so on. Some people think that, in case of more than one network interface, the network card that is integrated on the motherboard will be eth0. This is not true at all. In case of a point-to-point connection, you'll see ppp0.
After locating the adapter you want to configure, you'll use the ifconfig command to assign TCP/IP configuration values to the network interface. Normally, we'll need to assign two or three values: the IP address, the network mask and sometimes the broadcast address.
We'll assume we need to set an IP address of 10.10.10.8 with the subnet 255.255.255.0 to the eth0 network adapter. (Network mask and subnet mask are the same thing, and you might find other similar terms that refer to them.) This is done by entering this command:
ifconfig eth0 10.10.10.8 netmask 255.255.255.0
Defining the broadcast address is important too, because the ifconfig command sometimes sets a very weird broadcast address. In our case, the command will be:
ifconfig eth0 10.10.10.8 netmask 255.255.255.0 broadcast 10.10.10.255
Now, there are two simple ways to see if you managed to configure your Ethernet interface. One is to execute ifconfig in a terminal (and you'll see all the interfaces that are up), and the other is to execute ifconfig followed by the name of the interface you want to check. In our case, "ifconfig eth0" will show the configuration of eth0.
Your configuration to eth0 will be reset if you reboot. Normally, you will not want to execute this command every time you boot your Linux computer. In most Linux distributions, there is a script in /etc called rc.local that is executed the last, so that it will not get overwritten by other scripts. Adding your ifconfig command here will setup your interface every time the system boots.
You can use the ifconfig command to shutdown an interface or to activate it. To do this, you use the command this way:
fconfig eth0 down
ifconfig eth0 up
If you want to go online, the ifconfig command is not enough. You'll still have to configure the gateway that the system should use. This is done using the "route" command. Assuming that the gateway we want to use is 10.10.10.1, the command for using this address as the default gateway is:
route add default gw 10.10.10.1. Adding this line in the rc.local script is also recommended if you want to have your Internet connection setup on your machine. You can verify if the correct route was added with the "route" command.
This 'How-to' only demonstrates a hypothetical situation of setting up a network interface and an Internet connection. The settings here should be adapted to fit your situation, and if you understand how do the commands explained here work, you won't have a problem configuring your network. Most probably you'll be using graphical software from your Linux distribution, but knowing this stuff might come in handy sometimes, and it is really helpful for debuging.