Title
Networking
Network Interfaces
A network interface serves as the point of interconnection between a device and a network.
+--------------------------------------------------------+
| COMPUTER SYSTEM |
| |
| +------------------------------------------------+ |
| | OPERATING SYSTEM | |
| | | |
| | +--------------+ +--------------+ | |
| | | APPLICATION | <-> | APPLICATION | | |
| | +--------------+ +--------------+ | |
| | ... | |
| | +----------------------------------------+ | |
| | | NETWORK STACK | | |
| | +----------------------------------------+ | |
| +------------------------------------------------+ |
| | | |
| +-------+-------+ +-------+-------+ |
| | NETWORK CARD | | WIRELESS CARD | |
| +---------------+ +---------------+ |
| |
+--------------------------------------------------------+
Networking Commands:
Networking commands are essential for configuring, managing, and troubleshooting network connections on a system. Below are some commonly used commands and their typical use-cases:
ifconfig
Historically one of the primary tools for network configuration on Linux systems, ifconfig displays information about all active network interfaces, including their IP addresses, MAC addresses, and more.
Usage:
ifconfig # To view details of all network interfaces.
ifconfig eth0 # To view details of a specific interface.
Note: While ifconfig is still widely used, it's considered deprecated in many modern Linux distributions in favor of the ip command.
ip
The ip command is a versatile and powerful tool for network administration, replacing functionalities previously offered by ifconfig, route, and others.
Usage:
ip addr show # Display IP addresses and Interfaces.
ip route show # Display routing table.
ip link show # List all network interfaces.
ip -s link # Show statistics for interfaces including sent&received packet details.
ping
The ping command is a network diagnostic tool used to test the connectivity between your computer and another host, usually specified by an IP address or a domain name. It works by sending ICMP echo request packets to the target host and waits for a reply.
Usage:
ping google.com # Send multiple ping requests using the ICMP protocol.
ping -c 5 google.com # Limit the number of ICMP packets.
ping -t 5 google.com # Specify Timeout Period (in seconds).
netstat
This tool provides network statistics. It's useful for displaying active network connections, listening ports, and network protocol statistics.
Usage:
ss
The ss (socket statistics) tool is a CLI command used to show network statistics. It is a simpler and faster version of the now obsolete netstat command
Usage:
traceroute
traceroute helps in identifying the route taken by packets across a network. It's particularly useful for troubleshooting network slowdowns and failures.
Usage:
traceroute google.com # List all servers the network traffic goes through.
traceroute -m 30 google.com # To set maximum number of hops (routers).
traceroute -T google.com # Traceroute uses ICMP to use TCP or UDP use -T or -U.
traceroute -w 5 google.com # Set how long to wait for a response from each hop.
Network Manager daemon
Network Manager is the default networking service on Linux systems responsible for managing network configurations, as it manages connection profiles. You can also modify network profiles by editing the connection's configuration file in /etc/NetworkManager/system-connections/.
While nmclicommands communicate directly with NetworkManager to implement modifications immediately, connection file edits are not implemented until NetworkManager is asked to reload the configuration file. With manual editing, you can create complex configurations in steps, and then load the final configuration when ready.
- CLI:
nmclilets you handle all networking tasks from the terminal. - Text-based UI with
nmtui
+------------+ +-------------+ +------------+
| | | | | |
| User GUI <------> Network <-----> Network |
| Tools | | Manager | | Interfaces |
| (nmtui) | | Daemon | | (eth0, wlan0,..)
| | | | | |
| | | | | |
+------------+ +------^------+ +------------+
|
|
+----v----+
| |
| D-Bus |
| |
+----^----+
|
|
+-----v------+
| |
| System |
| Services |
|(DNS, DHCP, |
| VPN,...) |
| |
+------------+
Useful NetworkManager Commands:
Configure a Static IP Address
Setting a static IP can be essential for devices that should have a consistent IP, like servers or specific workstations. Here's the command structure:
nmcli connection add con-name [interface] \
type ethernet \
ifname [interface] \
ipv4.method manual \
ipv4.addresses [IP address]/[network prefix] \
ipv4.gateway [default gateway] \
ipv4.dns [google dns]
Example:
**nmcli connection add con-name static-eth0 \
type ethernet \
ifname ens33 \
ipv4.method manual \
ipv4.addresses 192.168.1.207/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns 8.8.8.8**
-
A specific value can be added to the list or deleted from the connection settings by adding a plus (+) or minus (-) symbol to the start of the setting name. If a plus or minus is not included, then the specified value replaces the setting's current list.
nmcli con mod static-eth0 +ipv4.dns 8.8.4.4⇒ To modify (append) ipv4.dns attribute
To modify connection
**nmcli connection mod "Wired connection 1" \
ipv4.addresses 172.25.250.11/24 \
ipv4.gateway 172.25.250.254 \
ipv4.dns 172.25.250.254 \
ipv4.method manual \
connection.autoconnect yes**
nmcli connection modify "Wired connection 1" connection.autoconnect no⇒ To disable the original connection auto-starting at boot
You must reactivate the New / Modified connection
-
nmcli con up “Wired connection 1”⇒ Deactivates & reactivates only that specific connection immediateOR
-
nmcli connection reload⇒ If u edited network profiles manually/etc/ NetworkManager/system-connections/OR
-
systemctl restart NetworkManager⇒- NetworkManager is stuck, buggy, or behaving strangely.
- You modified core configs under
/etc/NetworkManager/NetworkManager.conf
Configure Hostname
Specify a static hostname in the /etc/hostname file. Use the hostnamectl command to
modify this file and view the system's fully qualified hostname. If this file does not exist, then the
hostname is set by a reverse DNS query when an IP address is assigned to the interface.
Usage:
hostname # Display the current hostname.
hostnamectl status # Display the host details
hostnamectl set-hostname name # Change hostname to name
Understanding DNS
- Before resorting to DNS servers, a computer will first check its local
/etc/hostsfile to see if there's a stored mapping for the requested domain to an IP address. - If the
/etc/hostsdoesn't have the needed mapping, the system consults the/etc/resolv.conffile to determine which DNS server it should query. - The computer sends a request to the identified DNS server to fetch the corresponding IP address for the domain.