From charlesreid1

networking

ping

Okay, you have managed to run ping. You have even figured out how to use the -c flag. In this case, ping will attempt four times, stop, and then report some basic statistics to you.

Knowing how to check whether or not you're connected is one thing, but what do you do when you're not? Or what if your network connection is active, but reports invalid information and you need to reconfigure it?

First, let's explore how to check our current configuration. In Debian, the file that controls the network devices by default is the following:

/etc/network/interfaces

Depending on several variables, which include how you configured your Debian installation, this file may be created differently. First, you may see several interfaces listed, such as your loopback adapter, wired Ethernet, and wireless. If you have more than one wired interface, you'll see any additional adapters here as well. This file is, simply put, a configuration file. It's a text file that contains information that the underlying Linux system understands, and causes a device to be configured as designated in the file.

To edit files such as these, there are many Linux text editors available, both GUI and terminal based. My personal favorite is vim, though many administrators typically start off with nano. The nano text editor is fairly easy to use, though very light on features. Alternatively, vim has many more features than nano but is a bit harder to get used to. Take your pick. To open a file in nano, all you need to do is type nano along with the name of a text file you would like to edit. If the file doesn't exist, the command will create it if you save the file. In the case of our /etc/network/interfaces file, the command will be similar to this:

# vim /etc/network/interfaces

continuing

back to the subject of our /etc/network/interfaces file. It's important to note that this file is not required for the purposes of ethernet and wireless adapters. If you see nothing in this file at all (other than the loopback device) it means that the network connections are being managed by Network Manager. Network Manager is a graphical tool for managing client-side network connections (which we'll discuss later in this chapter). For our purposes in this section, Network Manager is typically installed when you decide to include a graphical desktop environment when setting up Debian for the first time. If you did opt for a graphical environment (such as GNOME, Xfce, and so on), then Network Manager was more than likely set up for you and is handling the job of configuring your interfaces. If your interfaces file is blank other than the entry for the loopback adapter, then that means Network Manager is handling this task.

With Debian, it's extremely common to see installations in the wild with no graphical environment installed at all. A GUI is usually not necessary for the server to fulfill its purpose. A typical Linux administrator will configure a server with the minimum required packages for it to do its job, which often will not include a desktop environment. In this case, Network Manager may not be installed at all. If it's not, the /etc/network/interfaces file will then be responsible for setting up the connection. In other cases, perhaps Network Manager is installed, but was disabled by the administrator whom configured the network connections in this file instead.

So, when should you use Network Manager, and when should you just configure your connections in the interfaces file? In the case of end-user workstations (desktops and laptops), Network Manager is almost always preferred. In the case of servers, setting up the configuration in /etc/network/interfaces is preferred, especially when setting up a static IP address.

We've discussed what the interfaces file is, and when you'd want to use it. Now, let's take a look at some various types of configurations you can expect to see. First, let's gander at the interfaces file when only the local loopback adapter is listed:

$ cat /etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback

In this example, the machine most likely has Network Manager in use, as neither the wired (typically eth0) or wireless (typically wlan0) interfaces are shown. To verify this, we can check to see if Network Manager is running via the following command:

$ ps ax | grep NetworkManager

If Network Manager is running, you might see an output like this:

446 ?        Ssl    0:00 /usr/sbin/NetworkManager --no-daemon

That mystery is solved; the machine uses Network Manager, so there is no configuration for eth0 or wlan0 stored in /etc/network/interfaces. Now, let's take a look at an example from a machine where Network Manager is not being used. To configure eth0 in such an installation, the interfaces file would look similar to this:

# The loopback network interface
auto lo
iface lo inet loopback

# Wired connection eth0
auto eth0
iface eth0 inet dhcp


manual static

# The loopback network interface
auto lo
iface lo inet loopback

# Wired connection eth0
auto eth0
iface eth0 inet static
    address 10.10.10.12
    netmask 255.255.248.0
    network 10.10.10.0
    broadcast 10.10.10.255
    gateway 10.10.10.1

the following line changed:

iface eth0 inet static

static, not dhcp

if you declare dhcp, all other configuration details ignored

next declare ip address, 10.10.10.12

declare subnet mask to 255.255.248.0

declare the network we're joining to 10.10.10.0

declare the broadcast ID as 10.10.10.255

decalre the gateway as 10.10.10.1

now restart networking service

$ systemctl restart networking.service

or 

$ service networking restart

figure out what networking interfaces are available

$ ifconfig 

or 

$ ip addr show