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.1domainentry defines the domain name assigned to the network- system appends this domain name to any host names you specify, by default
searchentry defines any additional domains used to search for host namesnameserverentry defines DNS server assigned to your network- can have multiple DNS servers
- just add multiple
nameserverentries
- this file may reset at reboot
/etc/hostscan be used to manually enter connections to hosts/etc/nsswitch.conffile 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:
nmtuiprovides a simple text-based menu tool- displays a stripped-down version of the GUI tool
nmcliprovides 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
ethtooldisplays Ethernet settings for a network interface- by default, displays current configuration settings
- can change speed, duplex, and auto negotiation
ifconfigdisplays or sets the IP address and netmask values for a network interface- legacy command
ipdisplays 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
iwconfigcommand
- e.g.,
iwconfigdisplays 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
- assign a wireless SSID and encryption key:
iwlistdisplays all wireless signals your wireless card detects- e.g.,
iwlist wlan0 scan
- e.g.,
routedisplays or sets the default router address- e.g.,
route add default gw 192.168.1.254
- e.g.,
- common DHCP client programs for Linux:
dhcpcd- most popular
dhclientpump
Basic Network Troubleshooting
- can test network connectivity with
pingandping6
Finding Host Information
- can test host name with
hostcommand- 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
- e.g.,
digcommand displays all DNS data records associated with a specific host or network- e.g.,
dig www.linux.orgdig linux.org MX
- e.g.,
nslookupdisplays DNS information for multiple servers or domains- can run in interactive mode
Advanced Network Troubleshooting
- two ways to see active network connections:
netstatcommand lists all open network connections on the system-tfor TCP connections-ufor UDP connections-lfor which applications on are listening on which ports-sfor statistics for different types of packets
sscommand can link which system processes are using which network socket that are active- a socket is a program connection to a port
-anptoption displays both listening and established TCP connections and the associated process