Managing Network Connections on Linux


Configure Network Features

  • need to configure 5 things to interact on a network:
    • host address
    • network subnet address
    • default router (aka gateway)
    • system host name
    • Domain Name System (DNS) server address
  • 3 ways to configure this information:
    • manually editing network configuration files
    • using GUI tool
    • using command-line tools

Graphical Tools

The Network Manager tool is a common program on many Linux distributions to provide a GUI for defining network connections.

  • starts automatically at boot time
  • appears in system tray
    • wired connection shows a mini network with blocks icon
    • wireless connection shows an empty radio signal
      • click the icon to connect to your wireless access point
    • click icon > Edit Connections to edit network connection settings
  • In the Network Connections window, can select a connection then click edit to edit its information

Manually Editing DNS Configuration

  • can manually define a DNS server in /etc/resolv.conf
domain mydomain.com
search mytest.com
nameserver 192.168.1.1
  • domain entry defines the domain name assigned to the network
    • system appends this domain name to any host names you specify, by default
  • search entry defines any additional domains used to search for host names
  • nameserver entry defines DNS server assigned to your network
    • can have multiple DNS servers
    • just add multiple nameserver entries
  • this file may reset at reboot
  • /etc/hosts can be used to manually enter connections to hosts
    • /etc/nsswitch.conf file defines whether the Linux system checks this file before or after using DNS to look up the host name

Command-Line Tools

Network Manager CLI Tool

  • Network Manager has 2 CLI tools:
    • nmtui provides a simple text-based menu tool
      • displays a stripped-down version of the GUI tool
    • nmcli provides a text-only command-line tool
      • displays current network devices and their settings, by default
  • both help guide through setting up the required network information

Traditional Command-Line Tools

  • ethtool displays Ethernet settings for a network interface
    • by default, displays current configuration settings
    • can change speed, duplex, and auto negotiation
  • ifconfig displays or sets the IP address and netmask values for a network interface
    • legacy command
  • ip displays or sets the IP address, netmask, and router values for a network interface
    • e.g., ip address show
    • set host address and netmask for an interface:
      • ip address add 10.0.2.15/24 dev enp0s3
    • set default router for an interface
      • ip route add default via 192.168.1.254 dev enp0s3
    • make an interface active
      • ip link set enp0s3 up
    • before assigning an address to a wireless interface, must first use the iwconfig command
  • iwconfig displays or sets the SSID and encryption key for a wireless interface
    • assign a wireless SSID and encryption key:
      • iwconfig wlan0 essid "My Network" key s:mypassword
  • iwlist displays all wireless signals your wireless card detects
    • e.g., iwlist wlan0 scan
  • route displays or sets the default router address
    • e.g., route add default gw 192.168.1.254
  • common DHCP client programs for Linux:
    • dhcpcd
      • most popular
    • dhclient
    • pump

Basic Network Troubleshooting

  • can test network connectivity with ping and ping6

Finding Host Information

  • can test host name with host command
    • e.g., host www.linux.org
    • queries the DNS server to determine the IP addresses assigned to the specified host name
    • returns all IP addresses associated with host name by default
    • can specify IP address to find the associated host name
      • host 107.170.40.56
  • dig command displays all DNS data records associated with a specific host or network
    • e.g., dig www.linux.org
      • dig linux.org MX
  • nslookup displays DNS information for multiple servers or domains
    • can run in interactive mode

Advanced Network Troubleshooting

  • two ways to see active network connections:
    • netstat command lists all open network connections on the system
      • -t for TCP connections
      • -u for UDP connections
      • -l for which applications on are listening on which ports
      • -s for statistics for different types of packets
    • ss command can link which system processes are using which network socket that are active
      • a socket is a program connection to a port
      • -anpt option displays both listening and established TCP connections and the associated process