Skip to main content
Engineering LibreTexts

10-C.3: Network Connection

  • Page ID
    40577
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    EXAM OBJECTIVES COVERED

    1.3 Given a scenario, configure and verify network connection parameters.
    4.1 Given a scenario, analyze system properties and remediate accordingly.

    Configuring the System Hostname

    The hostnamectl command provides a proper API used to control Linux system hostname and change its related settings. The command also helps to change the hostname without actually locating and editing the /etc/hostname file on a given system.

    Using the hostnamectl command is the topoic of this video, just a quick overview and some examples of usage.

     

    Syntax:

    hostnamectl [ OPTIONS ] COMMAND ....
    

    Command Options:

    Options Meaning
    --no-ask-password Do not query the user for authentication for privileged operations.
    --static, --transient, --pretty If status is invoked (or no explicit command is given) and one of these switches is specified, hostnamectl will print out just this selected hostname.
    -H, --host= Execute the operation remotely. Specify a hostname, or a username and hostname separated by "@", to connect to. The hostname may optionally be suffixed by a port ssh is listening on, separated by ":", and then a container name, separated by "/", which connects directly to a specific container on the specified host.
    -M, --machine= Execute operation on a local container. Specify a container name to connect to, optionally prefixed by a user name to connect as and a separating "@" character.
    -h, --help Print a short help text and exit.
    --version Print a short version string and exit.

    Where COMMAND can be any of the following:

    • status: Used to check current hostname settings.
    • set-hostname NAME: Used to set system hostname.
    • set-icon-name NAME: Used to set icon name for host.
    • set-chassis NAME: Set chassis type for host.

    Types of hostname:

    • Static: Assigned by system admin and used to initialize the kernel hostname during boot time.
    • Dynamic or Transient: Assigned by DNS server or DHCP server during run time.
    • Pretty: A high-level hostname assigned by system admin or end-user.

    The example below shows the current status of the server. We then change the Static name to PbmacUbuntu, which can be seen in the second status command. However, notice that the second status query shows a difference between the static hostname and the transient hostname.

    pbmac@pbmac-server $ hostnamectl status
       Static hostname: pbmac-server
             Icon name: computer-desktop
               Chassis: desktop
            Machine ID: 75d57d2bcd2831ebf58bcc1a000008d4
               Boot ID: 688e9be968c34bffa95173e1d3e1effe
      Operating System: Ubuntu 18.04.4 LTS
                Kernel: Linux 4.15.0-91-generic
          Architecture: x86-64
    pbmac@pbmac-server $ sudo hostnamectl set-hostname PbmacUbuntu --static
    pbmac@pbmac-server $ hostnamectl status
       Static hostname: PbmacUbuntu
    Transient hostname: pbmac-server
    

    The static host name is the traditional hostname which can be chosen by the user, and is stored in the /etc/hostname file. The “transient” hostname is a dynamic host name maintained by the kernel. It is initialized to the static host name by default, whose value defaults to “localhost.” It can be changed by DHCP or DHCP at runtime.

    IP Configuration

    Any computer that needs to connect to a network must have a couple of pieces of information: 1) an IP address; 2) a hostname; and 3) a MAC address. We discussed the hostname in the previous section. The MAC address is a hardware address that is assigned to your network interface by the manufacturer. That leaves the IP address to discuss.

    IP stands for Internet Protocol. An Internet Protocol address, or IP address is a unique identifier given to every machine in a network. An IP address serves two primary functions. It is used as an interface identification for a network of machines and it also serves to provide a location of that machine, much like a physical address for a home or business. Because an IP address is a unique identifier, it allows computers to send and receive information to and from specific computers in a given network.

    Each device on an IP network requires three different pieces of information in order to correctly communicate with other devices on the network: an IP address, a subnet mask, and a broadcast address. You will usually see each of these numbers written as four "octets" (e.g. 198.41.12.151, 255.255.255.0, and 198.41.12.255). Each device also needs a MAC address.

    Linux Network Manager

    NetworkManager is a program for providing detection and configuration for systems to automatically connect to networks. NetworkManager's functionality can be useful for both wireless and wired networks. For wireless networks, NetworkManager prefers known wireless networks and has the ability to switch to the most reliable network. NetworkManager-aware applications can switch from online and offline mode. NetworkManager also prefers wired connections over wireless ones, and has support for modem connections and certain types of VPN. NetworkManager was originally developed by Red Hat and now is hosted by the GNOME project.

    The nmcli Command

    The nmcli command is a tool which is used for controlling NetworkManager. nmcli command can also be used to display network device status, create, edit, activate/deactivate, and delete network connections.

    It is used in scripts, and instead of manually managing the network connections it utilizes NetworkMaager via nmcli. Servers use the nmcli command on headless machines since it can be used to control system-wide connections via NetworkManager without a GUI.

    Syntax:

    nmcli [ OPTIONS ] OBJECT { COMMAND | help }

    Where the OBJECT can be any one of the following:

    • g[eneral] - NetworkManager's general status and operations
    • n[etworking] - overall networking control
    • r[adio] NetworkManager - radio switches
    • c[onnection] - NetworkManager's connections
    • d[evice] - devices managed by NetworkManager
    • a[gent] - NetworkManager secret agent or polkit agent
    • m[onitor] - monitor NetworkManager changes

    Options:

    Options Option Meaning
    -t[erse] terse output
    -p[retty] pretty output
    -m[ode] tabular|multiline output mode
    -c[olors] auto|yes|no whether to use colors in output
    -f[ields] <field, 1field2 ...>|all|common specify fields to output

    The nmcli command can show simple status of the system, or it can show all of the current connections.

    pbmac@pbmac-server $ nmcli device status
    DEVICE   TYPE      STATE      CONNECTION         
    enp0s25  ethernet  connected  Wired connection 1 
    lo       loopback  unmanaged  --       
    

    The nmtui Command

    nmtui is an alternative to nmcli. nmtui is short for Network Manager Text User Interface, and is another handy tool that allows system administrators to configure network interfaces in Linux using a graphical display. The nmtui command can be run directly from the terminal or even in putty.

    nmtui interface
    Figure \(\PageIndex{1}\): Network Manager TUI. ("Network Manager" by Patrick McClanahan is licensed under CC BY-SA 4.0)

    With this interface you use the arrows keys on the keyboard to move through the list, or use the Tab key to move to OK and then hit the Enter key. It takes a bit of getting used to - but if you do NOT have a GUI installed, you can still use tools like this.

    The video compares the ifconfig command and the newer ip command.

    The ifconfig Command

    The ifconfig command is used to configure the kernel-resident network interfaces. It is used at the boot time to set up the interfaces as necessary. After that, it is usually used when needed during debugging or when you need system tuning. Also, this command is used to assign the IP address and netmask to an interface or to enable or disable a given interface.

    Syntax:

    ifconfig [ OPTIONS ] [INTERFACE]
    

    The options are quite numerous, so it is suggested that you use the man page to read up on the available options.

    Newer versions of some Linux distributions don’t have ifconfig command pre-installed, since it is being replavced by the ip command. So, if there is an error “ifconfig: command not found” use the system's package install utility to install the package.

    The ip Command

    The ip command in Linux is present in the net-tools which is used for performing several network administration tasks. IP stands for Internet Protocol. This command is used to show or manipulate routing, devices, and tunnels. It is similar to, and replaces, the old ifconfig command. It is much more powerful with more functions and facilities attached to it. The ip command is used to perform several tasks like assigning an address to a network interface or configuring network interface parameters.

    It can perform several other tasks like configuring and modifying the default and static routing, setting up tunnel over IP, listing IP addresses and property information, modifying the status of the interface, assigning, deleting and setting up IP addresses and routes.

    Syntax:

    ip [ OPTIONS ] OBJECT { COMMAND | help }
    

    Again, the options are numerous, so please check out the man page for this command.

    Where the OBJECT can be any one of the following:l[ink] – used to display and modify network interfaces.

    • addr[ess] – used to display and modify protocol addresses (IP, IPv6).
    • r[oute] – used to display and alter the routing table.
    • n[eigh] – used to display and manipulate neighbor objects (ARP table)

    The following examples show several uses of the ip command. The first examples shows the interface and its status. Then both the IPv4 and IPV6 addresses are displayed along with the address duration (addresses assigned by DHCP servers can expire after a predetermined amount of time).

    pbmac@pbmac-server $ ip address show enp0s25
    2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
        link/ether bc:30:5b:ca:95:8a brd ff:ff:ff:ff:ff:ff
        inet 192.168.1.6/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s25
           valid_lft 68970sec preferred_lft 68970sec
        inet6 fe80::2e86:9a11:9c02:4a5/64 scope link noprefixroute 
           valid_lft forever preferred_lft forever
    pbmac@pbmac-server $ ip link
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
        link/ether bc:30:5b:ca:95:8a brd ff:ff:ff:ff:ff:ff
    

    The second example simply shows the two interfaces, the loopback interface and the ethernet interface, and the status.

    Adapted from:
    "8.4. Using Hostnamectl" by Unknown, Fedora Documentation Project is licensed under CC BY-SA 3.0
    "hostnamectl command in Linux with Examples" by Suraj1994, Geeks for Geeks is licensed under CC BY-SA 4.0
    "NetworkManager" by Multiple Contributors, Arch Linux is licensed under CC BY-SA 3.0
    "nmcli command in Linux with Examples" by Suraj1994, Geeks for Geeks is licensed under CC BY-SA 4.0
    "ifconfig command in Linux with Examples" by rossoskull, Geeks for Geeks is licensed under CC BY-SA 4.0
    "ip command in Linux with examples" by raghavmangal22, Geeks for Geeks is licensed under CC BY-SA 4.0


    10-C.3: Network Connection is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?