sections in this module City College of San Francisco - CS260A
Unix/Linux System Administration

Module: Administration Basics I
module list

Network Information

This is not a course in networking. However, we must be able to do basic networking operations such as setting the hostname, making an alias for the localhost, and setting and getting basic network parameters. We will discuss this in this section. This is a very brief introduction that is not meant to be thorough in any way.

Most personal systems contain a single network interface. Some may contain two - a wireless interface and a hardwired one. Servers may have two hardwired interfaces. Each interface has a name and a physical address, called a MAC address. In addition, many modern systems may create one or more pseudo interfaces. These are network interfaces without an underlying hardware device. These interfaces either limit traffic to devices attached to the interface, between devices attached to two interfaces, or translate addresses so that traffic can be sent to the physical network interface. Each of these pseudo interfaces has [a pseudo] MAC address as well. We will find that these pseudo devices are used to create networks of virtual machines.

The simulated hardwired network interface on our virtual machines, which is the one we will use most often in this class, is normally called eth0. The physical network interface on the physical linux hosts, at the time of this writing, is normally eno1.

Querying network parameters

The traditional way of querying network parameters is using ifconfig. If you use it on one of our systems, however, you will get lots of output, since ifconfig outputs information about every interface, physical and pseudo. It is better to specify the interface you want, assuming you know its name:


[gboyd@nelson ~]$ ifconfig eno1
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 147.144.23.58  netmask 255.255.255.0  broadcast 147.144.23.255
        inet6 fe80::b6b5:2fff:febb:9f2c  prefixlen 64  scopeid 0x20<link>
        ether b4:b5:2f:bb:9f:2c  txqueuelen 1000  (Ethernet)
        RX packets 165878  bytes 69305421 (66.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 163515  bytes 13483427 (12.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 20  memory 0xfe400000-fe420000  

If you want to find out the name of your default interface, the easiest way at the command-line is to either run ifconfig without the interface name, and look for the real interface, or look at the interface(s) listed as physical files in /etc/sysconfig/network-scripts/ifcfg-*

[gboyd@nelson ~]$ ls /etc/sysconfig/network-scripts/ifcfg-*
/etc/sysconfig/network-scripts/ifcfg-eno1
/etc/sysconfig/network-scripts/ifcfg-lo

The important information in this output are the ip addresses (the familiar IPv4 address and the newer IPv6 address). These are output as the inet and inet6 addresses, the netmask (Mask), and the MAC Address of the interface (the HWAddr).

The more modern way of querying this information is using the program ip. Here you ask to show information on either the link (MAC) or IPv4 addrfrom the device eno1

[gboyd@nelson ~]$ ip addr show dev eno1
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether b4:b5:2f:bb:9f:2c brd ff:ff:ff:ff:ff:ff
    inet 147.144.23.58/24 brd 147.144.23.255 scope global dynamic eno1
       valid_lft 19342sec preferred_lft 19342sec
    inet6 fe80::b6b5:2fff:febb:9f2c/64 scope link
       valid_lft forever preferred_lft forever

[gboyd@nelson ~]$
[gboyd@nelson ~]$ ip link show dev eno1
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether b4:b5:2f:bb:9f:2c brd ff:ff:ff:ff:ff:ff
[gboyd@nelson ~]$

The /24 in the above output of the IPv4 address is the same as the 255.255.255.0 netmask output by ifconfig. To map host/domain names to ip addresses, DNS is used. The DNS servers currently configured to be used on the system are reflected in the file /etc/resolv.conf

[gboyd@nelson ~]$ cat /etc/resolv.conf
# Generated by NetworkManager
search acrc.ccsf.edu ccsf.edu
nameserver 147.144.23.68
nameserver 147.144.1.251
nameserver 147.144.1.252
[gboyd@nelson ~]$

You can also query this information using the GUI, and that is the easiest way to set it. Counter-intuitively, the networking parameters can be queried using the System->Preferences->Network Connections panel. (on RH7 it is in Applications->Sundry->Network Connections ).  On both systems this is available using the GUI program nm-connection-editor. You must open the appropriate network interface and edit the information. Here we are examining the settings for IPv4. The RH6 version is shown (the default interface there is eth0):

network connection panel showing settings for eth0

In this pane you can see that this machine's IP address is set manually. Most machines use DHCP for their IP address. If this machine were using DHCP, the machine's IP address would NOT appear in this panel, nor would its DNS servers! You would have to get them using the commandline tools ifconfig or ip.

You can make any changes you want here. Of course, you must have the root password to apply them.

As alluded to above, the information shown here is saved in configuration files in /etc/sysconfig/network-scripts, named for the interface - here, ifcfg-eno1.

A curses-style (text-based) program for editing network connections is also available. On RH6 it is system-config-network-tui. On RH7 it is nmtui. RH7 also has a command-line version nmcli.

Getting/setting the hostname

The hostname can be queried using the command hostname. To change it permanently you must edit the file  /etc/sysconfig/network (RH6) or /etc/hostname (RH7) The hostname will not be reset until you restart the machine. (or you can set it temporarily by adding the new hostname using the hostname command such as hostname foo.com):

RH6
RH7
$ cat /etc/sysconfig/network
HOSTNAME=nelson.acrc.ccsf.edu
NETWORKING=yes
NISDOMAIN=grinder
$ cat /etc/hostname
nelson.acrc.ccsf.edu
$ cat /etc/sysconfig/network
NISDOMAIN=grinder

Of course, this hostname must be available via DNS to be resolved to your machine. If you want to set your own hostname/domain that is visible only locally on your system (thus independent of DNS) you can easily do that by adding an alias in the /etc/hosts file. You can use this same technique to name individual systems on your own network. By propagating this file to each system and using static IP addresses you can avoid the need for a DNS server for your machines so long as you only want them visible to each other. Of course you are responsible for keeping the information consistent!

Prev This page was made entirely with free software on linux:  
the Mozilla Project
and Openoffice.org    
Next

Copyright 2015 Greg Boyd - All Rights Reserved.