What is network interfaces in linux

Setting Up Network Interfaces in Linux

Nowadays computer provides us a great deal of opportunities (of course, the majority of users can easily go without many of them), but with no exaggerations “surfing the net” represents one of the most important and essential ones. People who use Linux OS argue that given operating system is perfect for Web. In fact it’s hardly possible to disagree with them; however before you can start surfing the web the first thing you need to do is to configure network interfaces.

What are the network interfaces? They represent devices that are used to transmit and receive packages of data. The examples of network interface devices are: Ethernet card, ISDN adapter, modem and etc. You can imagine that a network interface is a mailbox or an end of pipe, where you can send information and receive an answer. The integral attribute of network interface is address.

Generally users encounter with IP (Internet Protocol) networks. In the given review we are going to consider IPv4 (4th version of IP addresses), which are still very popular among the end users. After that we will discuss how to setup a network connection in Linux, taking as an example Ethernet card (which presents an interface allowing to connect a PC to the net with the help of copper twisted pair cable with the data transfer speed of up to 1GB/s). You can setup other interfaces in a similar way. To setup the interface in Linux the following steps should be completed:

  • Physical installation of the card in the system (we suppose you’ve already done this step or the interface is in the motherboard of your computer; moreover don’t forget to plug in the cable as well)
  • Installation of the proper drivers, so Linux can work with your card
  • Specifying IP address and some other parameters, which are needed for IP network

In Linux OS network interfaces (as the majority of other devices) are set up with the help of text files, which can vary depending on distributions, for example:

Distribution Interface and routing setting
Debian /etc/init.d/network
Ubuntu /etc/network/interfaces
Slackware /etc/rc.d/rc.inet1
RedHat /etc/sysconfig/network-scripts/ifup-

We are going to review it by Ubuntu example.

All Linux network interfaces have unique alphanumeric identifiers. For Ethernet interfaces the identifier consists of “Eth” prefix and interface ordinal number, which is generally assigned by OS depending on the order of devices on PCI bus; however in some cases it can be changed. Linux can work (and, of course, assign an identifier) just with those devices, which have proper drivers installed. Run ifconfig command in the terminal. In case you see your network card in the list, it means that Linux installed the drivers. Here is the way a response you should get may look:

01 - ifconfig command

As you probably understood “eth0” means your network card. In case there are some network cards, for each one there will be an eth section with the order number.

Using dmesg | grep -i eth command you can specify the name of network interface that corresponds to your network card. Of course, it can be useful just in case you have several cards. Here is the way it looks:

02 - the name of interface

If you don’t see the card you need in the list, you will have to find and install the driver.

A driver is a small program that allows operating system to get the functionality of certain devices. Due to this fact the drivers for different operating systems differ from each other (still there are some exceptions, for instance, some drivers for Windows can be used in Linux as well).

In Linux drivers are implemented in the kernel by compilation or by installing special kernel module. Drivers are generally distributed in the same way as usual programs (in particular in the form of source code), but their installation may require some additional actions, thus it’s strongly recommended to get familiar with the README for a certain driver. The most probable sources for proper drivers are:

  • Webiste of device manufacturer
  • Website of your Linux distribution provider (in particular, update packages for Ubuntu, which include drivers, appear on a regular basis – drivers for some network cards you can find in the package linux-backports-modules-intrepid-generic).
  • Hackers or communities websites

The process of configuring network interface for working in IP networks includes defining the following parameters:

IP address of interface. It represents 4 decimal numbers that are separated by periods. For example, 10.9.8.7. In case you connect your computer to an existing network, the address should be taken from network administrator; but if you create your own network, it’s recommended to choose IP address from special range: 10.0.0.0-10.255.255.255, 172.16.0.0-172.31.255.255 and 192.168.0.0-192.168.255.255

Subnet mask (address mask). Given parameter is used to define the multitude of computer addresses, which are available in your network. If there is a necessity you can learn more here. In small networks the most common mask value is 255.255.255.0.

Gateway. If your network is going to have connection with other network (even with Internet), you need to define the address of routing computer (gateway), which is directly connected both with your network and the other one. All the data packages that are not masked by the above mentioned mask will be transferred to this router for redirection to the extranet.

Broadcast address. It’s used to send the data to all computers in your network at once. In most cases there is no need to specify it because the system can automatically calculate it.

DNS server address. It represents IP address of a server that transforms character names, which are convenient for users (for example, www.lampdocs.com, www.linux.com and etc), into appropriate IP addresses and vice versa. Generally such a server is maintained by your internet provider, moreover very often several servers are provided to ensure fault tolerance.

If the user wants to get rid of setting all the parameters, a special server can be created in the network – DHCP (Dynamic Host Configuration Protocol), which will automatically configure your network interface. Get in contact with the administrator of your network or your Internet provider to find out if there is a DHCP server. In case such a server doesn’t exist, you will need to specify all the settings manually; it’s not as hard to do and the procedure is almost the same as the one in Windows. Now we are going to show how you can do that in Ubuntu.

Источник

Demystifying ifconfig and network interfaces in Linux

This post explains ifconfig output of common developer’s box, paying special attention to parameters poorly explained in official documentation. It also slightly touches Linux network interfaces.

ifconfig

ifconfig is a command line tool for UNIX-like systems that allows for diagnosing and configuring network interfaces. At boot time, it sets up network interfaces such as Loopback and Ethernet. Most of the time, however, ifconfig is used for network diagnostics.

Before diving into details of its output, let’s first make clear what is an interface.

network interface

A network interface is a software interface to networking hardware. Linux kernel distinguishes between two types of network interfaces: physical and virtual.

Physical network interface represents an actual network hardware device such as network interface controller (NIC). In practice, you’ll often find eth0 interface, which represents Ethernet network card.

Virtual network interface doesn’t represent any hardware device and is usually linked to one. There are different kinds of virtual interfaces: Loopback, bridges, VLANs, tunnel interfaces and so on. With proliferation of software defined networks, virtual interfaces become wildly used.

Demystifying ifconfig output

Let’s have a look at ifconfig output for a developer’s box with installed Ubuntu and Docker.

$ ifconfig docker0 Link encap:Ethernet HWaddr 02:42:2d:66:fc:f1 inet addr:172.17.0.1 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::42:2dff:fe66:fcf1/64 Scope:Link UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:2 errors:0 dropped:0 overruns:0 frame:0 TX packets:3 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:152 (152.0 B) TX bytes:258 (258.0 B) eth0 Link encap:Ethernet HWaddr 08:00:27:31:65:b5 inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::3db9:eaaa:e0ae:6e09/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1089467 errors:0 dropped:0 overruns:0 frame:0 TX packets:508121 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:903808796 (903.8 MB) TX bytes:31099448 (31.0 MB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:9643 errors:0 dropped:0 overruns:0 frame:0 TX packets:9643 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:719527 (719.5 KB) TX bytes:719527 (719.5 KB) 
interfaces

There are 3 network interfaces on the box:

eth0 is a physical interface representing Ethernet network card. It’s used for communication with other computers on the network and on the Internet.

lo is a special virtual network interface called loopback device. Loopback is used mainly for diagnostics and troubleshooting, and to connect to services running on local host.

docker0 is a virtual bridge interface created by Docker. This bridge creates a separate network for docker containers and allows them to communicate with each other.

interface details

Let’s look closely at details of ifconfig output:

Link encap shows how packets are encapsulated for transmission. Most interfaces wrap packets in Ethernet frames.

HWaddr is hardware address of the ethernet interface (also known as MAC address).

inet addr is IPv4 address assigned to the interface.

Bcast is broadcast address for the interface.

Mask is network mask for the interface.

inet6 addr is IPv6 address assigned to the interface.

Scope is scope of IPv6 address. It can be link-local or global. Link-local address is used in local area network and is not routable. Global address is routable.

UP indicates that kernel modules related to the interface have been loaded and interface is activated.

BROADCAST indicates that interface is configured to handle broadcast packets, which is required for obtaining IP address via DHCP.

RUNNING indicates that interface is ready to accept data.

MULTICAST indicates that interface supports multicasting.

MTU is maximum transmission unit. IP datagrams larger than MTU bytes will be fragmented into multiple Ethernet frames.

Metric determines the cost of using the interface. Interfaces with lower cost have higher priority.

interface stats

RX packets is a total number of packets received.

RX errors shows a total number of packets received with error. This includes too-long-frames errors, ring-buffer overflow errors, CRC errors, frame alignment errors, fifo overruns, and missed packets.

RX dropped is a number of dropped packets due to unintended VLAN tags or receiving IPv6 frames when interface is not configured for IPv6.

RX overruns is a number of received packets that experienced fifo overruns, caused by rate at which a buffer gets full and kernel isn’t able to empty it.

RX frame is a number of misaligned frames, i.e. frames with length not divisible by 8.

TX packets is total number of packets transmitted.

TX errors , TX dropped and TX overruns are similar to RX equivalents.

TX carriers is a number of packets that experienced loss of carriers. This usually happens when link is flapping.

TX collisions is a number of transmitted packets that experienced Ethernet collisions.

TX txqueuelen is length of transmission queue.

RX bytes is a total number of bytes received over interface.

TX bytes is a total number of bytes transmitted over interface.

Summary

Despite being superseded by ip command, ifconfig is still commonly used and provides lots of useful details about network interfaces, both physical and virtual.

Источник

Читайте также:  Linux get driver list
Оцените статью
Adblock
detector