Lesson 18 of 29 ↓
- 1.Rhel 9 Administration Guide
- 2.Ubuntu Boot Process Guide
- 3.Linux Basic Commands Guide
- 4.Comprehensive Unix Shells Guide
- 5.Mastering Vim Deep & Practical Guide
- 6.Magic Numbers in Linux Deep Systems Guide
- 7.Wildcards & Globbing in Linux Deep Cli Guide
- 8.Linux Users & Groups Deep Administration Guide
- 9.Journaling in Linux Filesystems Deep Systems Guide
- 10.Getopt & Getoptlong Deep System-level Option Parsing Guide
- 11.Su Command in Linux Complete Guide with Environment Variables
- 12.Linux File Permissions and Ownership Complete Practical Guide
- 13.Ubuntu Package Management Apt Complete Guide
- 14.Bash Scripting Basics
- 15.Linux File System Essentials
- 16.Process and Thread Management
- 17.Session 10 : Introduction to Networking & the Application Layer
- 18.Linux Networking Cli & Introduction to Yocto for Machine Routing
- 19.Comprehensive Guide to Ssh (secure Shell)
- 20.Logical Volume Management (lvm) Guide
- 21.C Build Process & Libraries Guide
- 22.Archiving and Compression in Linux
- 23.Linux Package Managers: a Detailed Guide
- 24.Misra-c Guidelines Detailed Cheat Sheet
- 25.Mqtt Server Setup (pc as Server)
- 26.Detailed Explanation of Tty and Pts in Linux
- 27.Vim Cheat Sheet
- 28.Difference Between apt and apt-get
- 29.Difference Between apt Upgrade and apt Full-upgrade
12 min read
Linux Networking Cli & Introduction to Yocto for Machine Routing
This documentation covers essential concepts and commands for the Linux Networking Command Line Interface, specifically tailored for machine routing and embedded systems context.
Listing Network Interfaces
To view all network interfaces on the system, including those that are currently "down" (inactive), you can use two main approaches: the legacy net-tools or the modern iproute2 suite.
Method A: Using ifconfig (legacy)
Note
ifconfigis part of thenet-toolspackage. While widely used, it is technically deprecated in some modern distributions in favor of theipcommand.
Command:
ifconfig -aOutput Explanation: Below is a breakdown of the output fields using the provided example:
enp52s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether e8:80:88:29:6a:93 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0-
Interface Name (
enp52s0): Represents the physical Ethernet port. -
Flags
<UP...>: The interface is enabled logically, butRUNNINGis missing, indicating no cable is plugged in. -
ether: The MAC Address (Physical address) of the card.
-
RX/TX: Receive/Transmit statistics. Here they are 0, confirming no traffic.
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 152 bytes 14709 (14.7 KB)
...-
lo (Loopback): The internal virtual interface used for localhost communication.
-
inet 127.0.0.1: The standard localhost IPv4 address.
-
MTU 65536: Loopback supports huge packet sizes because traffic stays in memory.
wlp0s20f3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.165.26.87 netmask 255.255.255.0 broadcast 10.165.26.255
inet6 fe80::7cf3:464:1386:165c prefixlen 64 scopeid 0x20<link>
ether 30:89:4a:c2:74:1e txqueuelen 1000 (Ethernet)
RX packets 95989 bytes 101998303 (101.9 MB)
...-
wlp... (Wireless): The Wi-Fi interface.
-
flags
<...RUNNING...>: Indicates the interface is active and connected to a network. -
inet 10.165.26.87: The IPv4 address assigned to this machine.
-
RX/TX packets: Shows actual data traffic (101.9 MB received, 11.3 MB sent).
Method B: Using ip Link (modern Standard)
Note
This is the preferred method in modern Linux systems (Yocto/Embedded Linux often relies heavily on
iproute2).
Command:
ip link showOutput Explanation:
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-
state UNKNOWN: Normal for loopback interfaces (it doesn't need a physical carrier).
-
qdisc noqueue: No queuing discipline needed (instant traffic).
2: enp52s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
link/ether e8:80:88:29:6a:93 brd ff:ff:ff:ff:ff:ff-
NO-CARRIER: Confirms physical disconnection (cable unplugged).
-
state DOWN: The interface is administratively UP (enabled in OS), but physically DOWN.
-
qdisc fq_codel: Fair Queuing Controlled Delay (modern algorithm to prevent buffer bloat).
3: wlp0s20f3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000
link/ether 30:89:4a:c2:74:1e brd ff:ff:ff:ff:ff:ff-
state UP: The interface is fully operational and connected.
-
LOWER_UP: Physical layer (L1) is active.
Summary Comparison: ifconfig vs ip Link Show
| Feature | ifconfig |
ip link show |
|---|---|---|
| Package Suite | net-tools |
iproute2 |
| Status | Deprecated (Legacy) | Current Standard |
| OS Availability | May be missing in minimal Yocto images | Default in almost all modern Linux distros |
| Information Scope | Shows IP addresses (L3) and MAC (L2) together | Shows only Link/MAC (L2) details |
| Detail Level | Verbose, human-readable | Concise, precise, script-friendly |
| Secondary IPs | Does not reliably show multiple IPs per interface | Handles multiple addresses/aliases natively |
Interface Configuration & Management
This section covers how to manipulate the state of interfaces and assign addresses.
2.1 Enabling/disabling Interfaces
Purpose: Activate (bring up) or deactivate (take down) a specific network interface to allow or stop traffic.
Using ip (Modern):
# Bring interface UP
sudo ip link set dev <interface> up
# Bring interface DOWN
sudo ip link set dev <interface> down-
set: The action to modify the device. -
dev <interface>: Target device (e.g.,eth0,wlan0). -
up/down: The desired state.
Using ifconfig (Legacy):
sudo ifconfig <interface> up
sudo ifconfig <interface> down2.2 Configuring Ip Addresses
Purpose: Assign static IP addresses to network interfaces. This is common in server/embedded environments where DHCP is not used.
Using ip (Modern):
sudo ip addr add 192.168.1.100/24 dev <interface>
sudo ip link set <interface> up-
addr add: Command to append an address. -
192.168.1.100/24: CIDR Notation. This is crucial.-
192.168.1.100is the IP. -
/24represents the Subnet Mask (255.255.255.0).
-
-
Note: If you make a mistake, use
delinstead ofaddto remove it.
Using ifconfig (Legacy):
sudo ifconfig <interface> 192.168.1.100 netmask 255.255.255.0 up-
netmask: explicitly defines the mask (older style compared to CIDR). -
up: Can be combined in one line to activate the interface immediately.
Important
These changes are temporary. They will be lost after a reboot. For persistent configuration in Yocto/Linux, you would edit files like
/etc/network/interfacesor usesystemd-networkd/NetworkManager.
Hostname and Dns Configuration
Setting the identity of the machine and how it finds other machines.
3.1 Managing Hostnames
Purpose: Set or change the system’s name.
-
Temporary (Current Session only):
bash sudo hostname <newhostname> -
Persistent (Permanent across reboots):
bash sudo hostnamectl set-hostname <newhostname>hostnamectl: The systemd utility to query and change the system hostname and related settings.
3.2 Editing the Hosts File
File Location: /etc/hosts
Purpose: Local DNS resolution. The system checks this file before asking a DNS server. It maps hostnames directly to IP addresses.
Example Entry:
127.0.0.1 localhost
192.168.1.10 myserver.local myserver- If you ping
myserver, the system immediately knows it is192.168.1.10without needing network lookups.
3.3 Dns Setup
File Location: /etc/resolv.conf
Purpose: Defines the Nameservers (DNS servers) the system uses to resolve domain names (like google.com) to IPs.
Example Content:
nameserver 8.8.8.8
nameserver 1.1.1.1Warning
In modern systems (Ubuntu, Yocto with systemd),
/etc/resolv.confis often a symlink managed bysystemd-resolvedorNetworkManager. Editing it manually might work temporarily, but changes could be overwritten by the OS.
Testing Connectivity
4.1 Ping Command
Purpose: Test connectivity by sending ICMP echo requests to a target.
Command:
ping <ip-address or hostname>Explanation & Options:
-
Sends packets and reports round-trip time (RTT).
-
Press
Ctrl + Cto stop the command. -
Options like
-c <count>can limit the number of pings (e.g.,ping -c 4 google.com).
4.2 Traceroute
Purpose: Determine the route packets take to reach a network host.
Command:
traceroute <ip-address or hostname>Explanation & Options:
-
Displays each hop along the path.
-
Options like
-m <max hops>can set the maximum number of hops (e.g.,traceroute -m 15 google.com).
4.3 Mtr
Purpose: Combine the functionalities of ping and traceroute for real-time network path analysis.
Command:
mtr <ip-address or hostname>Explanation: Provides a continuously updated view of the route and latency at each hop. Options allow changing the reporting interval and packet size.
Analyzing Network Details
5.1 Netstat
Purpose: Display network connections, routing tables, interface statistics, and more.
Command:
netstat -tulpnExplanation & Options:
-
-t: Lists TCP connections. -
-u: Lists UDP connections. -
-l: Shows only listening sockets. -
-p: Displays the process using the socket. -
-n: Uses numeric addresses instead of resolving hostnames.
5.2 Ss Command
Purpose: Modern alternative to netstat for displaying socket statistics.
Command:
ss -tulpnExplanation: Uses similar options to netstat with improved performance and additional filtering capabilities.
5.3 Ip Route
Purpose: View and manage routing tables.
Command:
ip route showExplanation & Options:
-
ip route: Manages routes in the kernel. -
show: Lists all current routes. -
Adding a route:
bash sudo ip route add <destination> via <gateway> dev <interface>This command explains how packets to
<destination>are routed through a specified<gateway>on the given<interface>.
Network Diagnostics and Troubleshooting
6.1 Tcpdump
Purpose: Capture and analyze network packets in real time.
Command:
sudo tcpdump -i <interface>Explanation & Options:
-
-i <interface>: Specifies which interface to capture packets from. -
-w <file>: Write the output to a file (e.g.,-w capture.pcap). -
Filter expressions can narrow the capture (e.g.,
tcpdump -i <interface> port 80).
6.2 Nmap
Purpose: Network exploration and security auditing.
Command:
nmap <target-ip or hostname>Explanation & Options:
-
-F: Quick scan of the most common ports. -
-p <port-range>: Specify ports to scan (e.g.,-p 1-65535). -
-O: Attempt to detect the operating system of the target (requires sudo for some scans).
6.3 Ethtool
Purpose: Query and control network device settings.
Command:
sudo ethtool <interface>Explanation & Options:
-
Displays detailed information such as speed, duplex, and auto-negotiation settings.
-
To change settings:
bash sudo ethtool -s <interface> speed 100 duplex full autoneg offThis command sets the interface to 100Mb/s full duplex with auto-negotiation disabled.
6.4 Wireless (iw)
Purpose: Manage and troubleshoot wireless interfaces.
Commands:
-
List wireless devices:
code iw dev -
Display connection status:
bash iw <interface> link -
Scan for networks:
code iw <interface> scan
Explanation: The iw suite provides detailed control over wireless settings, replacing the older iwconfig tool.
Accessing Network Services
7.1 Ssh
Purpose: Securely access remote machines.
Command:
ssh username@server-ipExplanation & Options:
-
Establishes an encrypted connection to a remote host.
-
Options can include specifying a port (
-p <port>), using key authentication (-i <keyfile>), and more.
7.2 Ftp and Sftp
Purpose: Transfer files between systems.
-
FTP Command:
bash ftp <server-ip>Connects to an FTP server. Commands like
putandgetmanage file transfers. -
SFTP Command:
bash sftp username@server-ipSecure version running over SSH. It offers similar file operations as FTP but with encryption.
7.3 Telnet
Purpose: Test connectivity to a port (not recommended for secure operations).
Command:
telnet <server-ip> <port>Explanation: Connects to the specified port on the remote server, useful for basic connectivity tests.
7.4 Web Tools: Curl and Wget
Purpose: Retrieve data from web servers or perform HTTP/S operations.
-
curl:
bash curl -I [https://www.example.com](https://www.example.com)-
-I: Fetches only the HTTP headers. -
Can also be used for POST, PUT, and other HTTP methods.
-
-
wget:
bash wget [https://www.example.com/file.tar.gz](https://www.example.com/file.tar.gz)- Downloads files from the specified URL. Supports options for recursion, limiting download speed, and more.
Firewall and Security Tools
8.1 Iptables/nftables
Purpose: Manage packet filtering and NAT rules.
-
iptables Example:
bash sudo iptables -L -n -v-
-L: List all rules. -
-n: Display numerical addresses. -
-v: Verbose output.
-
-
nftables Example:
bash sudo nft list rulesetDisplays all rules currently active under nftables, the modern replacement for iptables.
8.2 Ufw and Firewalld
Purpose: Simplify firewall management.
-
ufw (Uncomplicated Firewall):
bash sudo ufw enable sudo ufw allow 22/tcp sudo ufw status verboseProvides a simplified interface to configure iptables rules, ideal for users seeking ease of use.
-
firewalld:
bash sudo firewall-cmd --permanent --add-port=22/tcp sudo firewall-cmd --reload sudo firewall-cmd --list-allUsed on many Red Hat-based systems to manage dynamic firewall rules with zones.
Key Configuration Files
Understanding where configuration changes persist is vital:
-
/etc/hostname– Contains the system’s hostname. -
/etc/hosts– Maps hostnames to IP addresses. -
/etc/resolv.conf– Specifies DNS server addresses. -
/etc/network/interfacesor/etc/sysconfig/network-scripts/ifcfg-*– Contains interface configuration for various distros. -
/etc/ssh/sshd_config– SSH daemon configuration. -
/etc/services– Lists service names and their associated ports.
Mapping Commands to Network Layers (osi)
Understanding where each command operates helps in diagnostics.
| OSI Layer | Layer Name | Common Devices/Concepts | Tools & Commands |
|---|---|---|---|
| Layer 1 | Physical | Cables, Cards, Link Speed | ethtool, ip link (state UP/DOWN) |
| Layer 2 | Data Link | MAC Addresses, VLANs, ARP | ip link, ip neigh, arp |
| Layer 3 | Network | IP Addresses, Routing, ICMP | ip addr, ip route, ping, traceroute |
| Layer 4 | Transport | TCP/UDP Ports, Sockets | netstat, ss, nmap |
| Layer 7 | Application | HTTP, FTP, SSH | curl, wget, ssh, telnet |
Logical Troubleshooting Workflow
If the network is down, follow this bottom-up approach:
-
Physical Check (L1): Is the cable plugged in? Is the interface UP?
-
Command:
ip link show(Look forLOWER_UP) -
Fix:
ip link set dev eth0 up
-
-
Link/Local Check (L2): Do you have a MAC address? Can you see neighbors?
- Command:
ip neigh(Are neighbors STALE or REACHABLE?)
- Command:
-
IP Configuration (L3): Do you have an IP address?
-
Command:
ip addr show -
Fix: Check DHCP or assign static IP.
-
-
Gateway/Routing (L3): Can you reach the router?
-
Command:
ip route show(Check fordefault via ...) -
Test:
ping <gateway_ip>
-
-
External Connectivity (L3): Can you reach the internet?
- Test:
ping 8.8.8.8(Google DNS)
- Test:
-
DNS Resolution (L7): Can you resolve names?
-
Test:
ping google.com -
Fix: Check
/etc/resolv.conf
-
Yocto & Embedded Specifics
In Embedded Linux (Yocto), networking is slightly different than Desktop Linux.
-
Persistence: The
ipcommands above are temporary. They reset on reboot. -
Network Managers: Yocto images typically use one of the following to manage network permanently:
-
systemd-networkd: (Modern, common) Configured in
/etc/systemd/network/*.network. -
ConnMan: (Common in mobile/IoT) specialized for embedded.
-
ifupdown: (Legacy) uses
/etc/network/interfaces.
-
Example: Persistent Static IP in systemd-networkd Create a file /etc/systemd/network/20-wired.network:
[Match]
Name=eth0
[Network]
Address=192.168.1.10/24
Gateway=192.168.1.1
DNS=8.8.8.8Additional Tools and Best Practices
13.1 Speedtest-cli
Purpose: Measure internet bandwidth using speedtest.net.
Command:
sudo apt install speedtest-cli # For Debian/Ubuntu
speedtest-cliExplanation: Run tests to determine your current download and upload speeds.
13.2 Additional Tips
-
Automation: Consider automating common tasks with shell scripts or configuration management tools like Ansible.
-
Documentation: Always consult the man pages (e.g.,
man ip,man tcpdump) for in-depth command options. -
Testing: Experiment in a lab environment before deploying changes to production networks.
Conclusion
This guide has expanded on basic Linux networking by providing detailed explanations for each command-line tool and its options. By understanding the OSI layers and following a logical troubleshooting workflow, you can effectively manage and debug any embedded Linux network.
Comments
Loading the discussion…