Chapter 39. Network Devices and Configuration

Objectives

  • Identify the network devices
  • Understand how the Operating System name the network devices and set its duties
  • Use ifconfig to 
    • Configure
    • Control
    • Query 
      • Network interface parameters
      • From the command line and from the System Configuration
  • Use the IP utility to display and control
    • Devices
    • Routing
    • Policy Based routing
    • Tunnelling
  • Know how to set default routes and static routes
  • Configure name resolution as well as run diagnostic utilities

Network Devices

These are the responsable for the network communication, each device is responsable for the communication among the outside (of the host) network and the local computer.

Unlike block and character devices, network devices are not associated with special device files, also known as device nodes, rather than having associated entries at /dev directory, they are know by their names

Their names consists of a type identifier followed by a number as in

  • eth0, eth1, eth2 
    • For Ethernet devices
  • wlan0, wlan1, wlan2
    • For Wireless devices
  • br0, br1, br2 
    • For bridge interfaces
  • vmnet0, vmnet1, vmnet2
    • For VMware virtual devices for communication with virtual clients

Sometimes multiple virtual devices can be associated with single physical devices, these are named with colons and numbers like

  • eth0:0
    • First alias on eth0 device

This is done to support multiple ip addresses on a single network card

Problems with Network Device Names

There is an issue with the names for the network devices, it is about the association of the network device name with the actual device. One of the methods is to associate the MAC address of the device with a given network device name (such as eth0 or eth1).

However this approach is a bit complex since requires tunning and its prune tu errors.

Predictable Network Interface Device Names

Is a way of naming the network devices and is related with the use of udev together with systemd. There are 5 types of names that devices can be given

  1. Incorporating Firmware or BIOS provided index numbers for on-board devices
    • Sample : eno1
  2. Incorporating Firmware or BIOS provided PCI Express hotplug slot index numbers
    • Sample : ens1
  3. Incorporating physical and/or geographical location of the hardware connection
    • Sample : enp2s0
  4. Incorporating the MAC address
    • Sample : enx7837d1ea46da
  5. Using the old classic method
    • Sample : eth0

Examples of the new naming schema

On a machine with two onboard PCI network interfaces that would have been eth0 and eth1

​$ ifconfig | grep enp
enp2s0: flags=4163<UP, BROADCAST, RUNNING, MULTICAST> mtu 1500
enp4s2: flags=4099<UP, BROADCAST, RUNNING, MULTICAST> mtu 1500

These names are correlated with the physical location of the hardware on the PCI system, making a

$ lspci
02:00.0 Ethernet controller: Marvel Technology Group Ltd.
04:02.0 Ethernet controller: Marvel Technology Group Ltd.

The triple of numbers at the beginning of each line stands, from the last output

  • Bus
    • 0
  • Device
    • 2 or 4
  • Function of the device
    • 00.0 or 02.0

Likewise for a wireless device that previously would have been wlan0

$ ifconfig grep wl
wlp3s0: flags=4163<UP, BROADCAST, RUNNING, MULTICAST> mtu 1500
$ lspci | grep Centrino
​03:00.0 Network controller: Intel Corporation Centriono...

​NIC Configuration files

Located in different directories according to the distribution

RHEL 6

Network

$ cat /etc/sysconfig/network
NETWORKING=yes
​HOSTNAME=bethe

Ifconfig eth0

$ cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="dhcp"
HWADDR="00:0C:29:25:4F:B3"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="5b53bee2-8fda-450d-729e-3996dd12ef7d"

​Ubuntu

​$ cat /etc/network/interfaces

Disable an interface Sample "eth0"

$ ifdown eth0

Enable an interface Sample "eth0"

$ ifup eth0

​Network interfaces can also be configured on the fly using either ifconfig or ip utilities, however such settings are not persistent

ifconfig

Display information about all interfaces

$ ifconfig

Display information about interface eth0

$ ifconfig eth0

Set the IP address to 192.168.1.50 on interface eth0

$ sudo ifconfig eth0 192.168.1.50

Set netmask to 24-bit

$ sudo ifconfig eth0 netmask 255.255.255.0

Bring eth0 up

$ sudo ifconfig eth0 up

Bring interface eth0 down

$ sudo ifconfig eth0 down

Set the MTU (Maximum Transfer Unit) to 1480 bytes for interface eth0

$ sudo ifconfig eth0 mtu 1480

​The IP Utility

Its the newer version of ifconfig, however it is far more capable and versatile because it uses netlink sockets rather than ioctl system calls.

ip can be used for a wide variety of tasks. It can be used to display and control devices, routing, policy-based routing and tunneling.

The basic syntax is :

ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] -batch filename

Main IP OBJECTS values
 

OBJECT Function
address IPv4 or IPv6 protocol device addres
link Network devices
maddress Multicast address
monitor Watch for netlink messages
route Routing table entry
rule Rule in the routing policy database
tunnel Tunnel over IP

Samples

Show information for all network interfaces

$ ip link

Show information for the eth0 network interface

$ ip -s link show eth0

Set the IP address for eth0

$ sudo ip addr add 192.168.1.7 dev eth0

Bring eth0 down

$ sudo ip link set eth0 down

Set the MTU to 1480 bytes for eth0

$ sudo ip link set eth0 mtu 1480

Set the network route

$ sudo ip route add 172.16.1.0/24 via 192.168.1.5

​Routing

Is the process of selecting paths in a network along which to send network traffic. The routing table is a list of routes to other networks managed by the system. It defines paths to all networks and hosts, sending remote traffic to routers

to see the current routing tables, one can use route

$ /sbin/route

or with ip

$ ip route

Default Route

Is the way the packages are sent through the network when there is not a specific rule at the routing table.

DHCP can be used to get information about this way. On Red Hat systems the file

/etc/sysconfig/network

Can be modified adding the line

GATEWAY=x.x.x.x

Or alternatively in 

/etc/sysconfig/network-scripts/ifcfg-ethX on a device specific basis in the configuration file for the individual NIC.

On Debian based systems we can set the gateway in 

/etc/network/interfaces
gateway=x.x.x.x

On both systems we can set the default gateway at run time with

$ sudo route add default gw 192.168.1.10 enp2s0
$ route

​Static Routes

Is a mechanism used to control the packet flow when there is more than one router or route. They are defined for each interface and can be either persistent or non-persistent.

When the system can access more than one router, or perhaps there are multiple interfaces, it is useful to selectively control which packets go to which router.

Either route or ip command can be used to set a non-persistent route as in

$ sudo ip route add 10.5.0.0/16 via 192.168.1.100
$ route

A persistent route can be set by editing

/etc/sysconfig/network-scripts/route-ethX
10.5.0.0/16 via 172.17.9.1

​Name Resolution

Is the act of translating hostnames to the IP addresses of their hosts. For example, a browser or email client will take 
training.alejandro.org
and resolve the name to the IP address of the server in order to transmit to and from that location.

There are two facilities for doing this translation

  • Static name resolution
    • Using /etc/hosts
  • Dynamic name resolution 
    • Using DNS servers

One sometimes also requires reverse resolution, converting an IP address to a host name.

/etc/hosts

Its a local DB of hotsnames and IP addresses. It looks like

127.0.0.1    localhost localhost4
192.168.1.100    mama 
192.168.1.102    papa
192.168.1.2        local printer

Generarly this file is checked before DNS resolution process, however the behavior can be modified in this file

​/etc/nsswitch.conf

DNS

Domain Name Service is basically a service that will map a name of a domain with his corresponding IP address. Local DNS service has a configuration file in

​/etc/resolv.conf

Modern systems will have a 

/etc/hosts.resolv

Network Diagnostic Utilities

  • ping
    • sends 64 byte test packets to designated hosts. Used to determine if the given host is reachable
  • traceroute
    • Used to display a network path to a destination. It shows the routers packets flow through the get to a host, as well as the time it takes for each hop
  • mtr
    • Combines ping and traceroute and created a continuos updated display like top
  • dig
    • Used to test DNS functionality. Note one can also use host or nslookup, older programs that also try to return DNS information about a host

LABORATORY