Inhaltsverzeichnis
Prerequisites
Access the command line/terminal with a user account that has sudo or root privileges!
1. The ip command (iproute2)
The ip command from the iproute2 suite is now the de facto standard for network configuration on Linux. It is more powerful and flexible than the outdated net-tools (ifconfig, route, arp) and communicates directly with the Linux kernel.
ip [Optionen] Objekt [Befehl]Object: What should the command be applied to? (e.g., addr, link, route, neigh)
Command: What action should be performed? (e.g., add, del, show, set)
1.1 ip addr (IP address management)
This object replaces ifconfig for displaying and assigning IP addresses. A major advantage is its simple support for CIDR notation (e.g., /24 instead of 255.255.255.0).
Display IP addresses:
Shows all assigned addresses (IPv4 and IPv6) of all interfaces.
ip addr showTemporarily add IP address:
Adds the IP 192.168.1.50 with subnet mask 255.255.255.0 (/24) to the interface eth0.
sudo ip addr add 192.168.1.50/24 dev eth0Remove IP address:
Removes the specific address from the interface again.
sudo ip addr del 192.168.1.50/24 dev eth01.2 ip link (Interface Management)
Used to control the physical or virtual network device. Here, interfaces are enabled, disabled, or hardware parameters are modified.
Display status of all interfaces:
Displays MAC addresses, MTU, and status (UP/DOWN).
ip link showEnable/disable interface:
Equivalent to unplugging or plugging in the cable (administratively).
# Deaktivieren
sudo ip link set eth0 down
# Aktivieren
sudo ip link set eth0 upChange MTU (Maximum Transmission Unit):
Changes the packet size, e.g., for Jumbo Frames or VPN optimization.
sudo ip link set eth0 mtu 1400Change MAC Address (Spoofing):
The interface usually needs to be disabled (down) first.
sudo ip link set eth0 address 00:11:22:33:44:551.3 ip route (Routing table)
Replaces the legacy `route` command and enables management of static routes and the default gateway.
Display routing table:
ip route showSet Default Gateway:
Routes all non-local traffic to the router 192.168.1.1.
sudo ip route add default via 192.168.1.1Add Static Route:
Routes traffic for the 10.10.10.0/24 network via gateway 192.168.1.254.
sudo ip route add 10.10.10.0/24 via 192.168.1.254Delete Route:
sudo ip route del 10.10.10.0/241.4 ip neigh (ARP table)
Replaces the arp command. It manages the Neighbor Table, which maps IP addresses to MAC addresses.
Display ARP cache:
Shows which devices are known in the local network.
ip neigh showDelete entry manually:
Useful when a device has changed its network card, but the cache still stores the old MAC.
sudo ip neigh del 192.168.1.1 dev eth02. ifconfig (veraltet)
The ifconfig (Interface Configuration) command is part of the older net-tools package. Although it is considered deprecated in modern Linux distributions and has been replaced by ip addr, it remains widely used in many existing systems, scripts, and among administrators familiar with UNIX systems.
ifconfig [Interface] [Optionen]Show all details:
Without arguments, it lists IP addresses, MAC addresses, MTU, and error packets (RX/TX errors) for all active interfaces.
ifconfigAssign IP address and subnet mask:
Unlike with the ip command, the subnet mask often needs to be explicitly specified here if it differs from the default.
sudo ifconfig eth0 192.168.1.50 netmask 255.255.255.0Enable/disable interface:
sudo ifconfig eth0 up
sudo ifconfig eth0 downEnable Promiscuous Mode:
Useful for network sniffers (such as Wireshark or tcpdump) so that the network card accepts all packets, not just those addressed to it.
sudo ifconfig eth0 promisc3. DNS diagnostics: dig & nslookup
DNS issues are among the most common network errors. These two tools are essential for checking name resolution.
dig (Domain Information Groper)
`dig` is the preferred tool for administrators. It provides the raw response from the DNS server, including header information, flags, and TTL (Time To Live). It is precise and ideal for scripting.
dig [Optionen] [Domain] [Typ]Standard query (A record):
Returns the IPv4 address of the domain.
dig google.comQuery a specific record type:
Often you need to check mail servers (MX) or text entries (TXT, e.g., for SPF/DKIM).
dig google.com MX
dig google.com TXTQuery a specific DNS server:
To test whether a specific server (e.g., an internal company server or Google Public DNS) responds correctly, use @ to bypass the local system configuration.
dig @8.8.8.8 google.comShort answer for scripts (+short):
Suppresses verbose output and displays only the result (the IP).
dig +short google.comTrace mode:
Recursively traces resolution from the root servers to the target.
dig +trace google.comnslookup
`nslookup` is older and available on almost all operating systems (including Windows and macOS). It is less verbose than `dig`, which makes it popular for quick checks. It has two modes: interactive and non-interactive.
nslookup [Optionen] [Domain]Quick Query:
Displays the server used and the IP address of the domain.
nslookup google.comInteractive mode:
If the tool is started without arguments, it opens its own shell (indicated by >). This allows multiple queries to be executed sequentially.
nslookup
> server 1.1.1.1 # Wechselt den DNS-Server zu Cloudflare
> set type=MX # Ändert den Abfragetyp auf Mail Exchange
> google.com # Führt die Abfrage durch
> exit # Beendet den Modus4. Network Statistics: netstat & ss
Monitoring open ports and active connections is essential to understand which services are running on a server or whether there are unwanted connections.
netstat (veraltet)
Although netstat is considered deprecated, it’s the tool many administrators type from muscle memory. It’s extremely versatile but can slow down on systems with thousands of connections.
netstat [Optionen]- The "standard" command for admins (-tulpn): This combination is the gold standard for finding out which process is using which port.
Bash
sudo netstat -tulpn-t: TCP-u: UDP-l: Listening (only server sockets in listening state)-p: PID/Program name (shows which program is using the port – requires sudo)-n: Numeric (no slow DNS resolution of hostnames)
- Display routing table: An alternative to route -n.
Bash
netstat -rn - Interface statistics: Shows TX/RX packets and error counters.
Bash
netstat -i
SS (Modern)
`ss (Socket Statistics) retrieves its information directly from the kernel via Netlink, making it extremely fast and efficient. It is the modern equivalent of netstat and offers powerful filtering options.
ss [Optionen] [Filter]- Show all open ports (equivalent to netstat -tulpn): The same flags work here as well.
Bash
sudo ss -tulpn - Show only established connections: Displays active data connections, not listening server sockets.
Bash
ss -t state established - Filter by specific ports: Shows only connections running on port 22 (SSH) or 80 (HTTP).
Bash
ss -t '( dport = :ssh or sport = :80 )'
5. Path Analysis: traceroute, tracepath & mtr
When a ping fails or is slow, these tools help identify exactly where along the path to the destination the issue lies (e.g., local router, ISP, or the destination’s data center).
Traceroute
The classic tool for tracing packet routes. It incrementally increases the TTL (Time to Live) value of packets to force a response from each router along the path.
traceroute [Optionen] [Host/IP]- Standard Trace (UDP): By default, Linux traceroute sends UDP packets. These are often blocked by firewalls (result: * * *). Bash
traceroute google.com - TCP Trace (Firewall Bypass): Uses TCP SYN packets (usually port 80). Since web traffic is often allowed, this often gets through firewalls that block UDP. Bash
sudo traceroute -T google.com - ICMP Trace: Behaves like the Windows tracert command. Bash
sudo traceroute -I google.com
tracepath
A simpler tool that is installed by default and does not require root privileges. A special feature is the detection of Path MTU.
tracepath [Host/IP]It indicates when the maximum packet size (MTU) changes along the path. This is important for diagnosing fragmentation issues (e.g., when VPN connections hang).
tracepath 8.8.8.8mtr (My Traceroute)
`mtr` is the most powerful of the three tools. It combines `ping` and `traceroute` into a single **interactive live view**. It continuously sends packets and updates the statistics.
mtr [Optionen] [Host/IP]TCP mode: Like traceroute, mtr can also use TCP to test firewalls. Bashsudo mtr --tcp google.com
Live diagnosis with report: Launches the GUI in the terminal. Displays packet loss (Loss%) and latency fluctuations (Jitter) per hop in real time.
Bashmtr google.com
Report Mode: Sends 10 cycles (-c 10) and then outputs a static report. Perfect for copying results into a support ticket.
Bashmtr -r -c 10 google.com
6. Connectivity tests: ping
The ping command is the "Hello World" of network diagnostics. It uses the ICMP (Internet Control Message Protocol) to check if a host is reachable and how long a data packet takes to travel there and back (Round Trip Time / RTT).
ping [Optionen] [Host/IP]- Standard ping: Under Linux, ping runs indefinitely (unlike Windows, where it stops after 4 packets) until it is interrupted with CTRL+C.
Bash
ping google.com - Limit count (-c): Essential for scripts. Sends exactly 5 packets and then exits automatically.
Bash
ping -c 5 google.com - Shorten interval (-i): By default, it waits one second. To detect network fluctuations faster, the interval can be shortened (root privileges are required for intervals below 0.2 seconds).
Bash
ping -i 0.2 google.com - Show only summary (-q): "Quiet" mode. Does not display each packet, but only the final statistics (packet loss, min/avg/max time).
Bash
ping -c 10 -q google.com
7. host & hostname
These commands are used for identification: host identifies external servers (DNS), hostname identifies the local system.
Host
A lean tool for DNS queries. It’s less verbose than dig and perfect for quick checks.
host [Optionen] [Domain/IP]- Simple resolution: Converts domain to IP address (shows both IPv4 and IPv6). Bash
host google.com - Reverse lookup (IP to name): Checks which domain name is behind an IP address. Useful for analyzing server logs. Bash
host 8.8.8.8 - Verbose output (-v): Verbose mode displays technical details similar to dig (flags, TTL, etc.). Bash
host -v google.com
Hostname
Displays or sets the name of the current system.
hostname [Optionen] [NeuerName]- Display current hostname:Bash
hostname - Display IP address of hostname (-I):Shows all local IP addresses of the device (very useful for quickly finding your own IP without parsing ip addr).Bash
hostname -I - Temporarily change hostname:Changes the name only until the next reboot. (For permanent changes, use hostnamectl set-hostname [Name] today).Bash
sudo hostname my-new-server
8. Routing & ARP (Legacy)
These are the classic tools from the net-tools package. While functional, they have largely been replaced by ip route and ip neigh.
route
Displays or manipulates the routing table.
route [Optionen]- Numeric routing table (-n): The -n option is important because otherwise, route will attempt to resolve IP addresses (such as router IPs) via DNS, which can lead to long wait times in case of connectivity issues.
Bash
route -n - Add default gateway: Sets the "exit" for all traffic that is not within the local network.
Bash
sudo route add default gw 192.168.1.1
ARP
Manages the ARP cache (Address Resolution Protocol). ARP translates logical IP addresses into physical MAC addresses on the local network (Layer 2).
arp [Optionen]- Display ARP table: Shows all devices in the local LAN that have recently been communicated with. Bash
arp -n - Delete entry (-d): If a device in the network has been replaced (same IP, new network card), the old ARP entry may cause issues. This forces a new resolution. Bash
sudo arp -d 192.168.1.50
9. Wireless & Cable: iwconfig & ifplugstatus
Specific tools for the physical connection layer.
iwconfig
The wireless equivalent of ifconfig. Used for configuring and diagnosing wireless interfaces. (Modern alternative: iw).
iwconfig [Interface] [Optionen]- Check status: Without arguments, it displays all interfaces. Important here: Bash
iwconfig- ESSID: The name of the connected Wi-Fi network.
- Link Quality/Signal level: The signal strength (e.g., -60dBm).
- Bit Rate: The current transmission speed.
- Change frequency/channel: Forces the card to a specific channel (useful for interference). Bash
sudo iwconfig wlan0 channel 6
ifplugstatus
A simple tool to check the physical status ("link beat") of a cable. Especially useful on headless servers to determine if the cable is loose or the switch port is dead.
ifplugstatus [Optionen] [Interface]- Check all interfaces: Returns 'link beat detected' if a physical connection exists. Bash
ifplugstatus
10. Data Transfer: curl & wget
Both tools are command-line download managers but have different focuses. wget is ideal for simple, robust downloads (including recursive ones), while curl is the "Swiss Army knife" for data transfers and API interactions.
wget (World Wide Web Getter)
wget is particularly powerful when dealing with unstable connections. It can resume downloads and mirror entire directory structures.
wget [Optionen] [URL]- Save file under a new name (-O): Downloads the file and renames it immediately.
Bash
wget -O my_archive.zip http://example.com/download.php?id=123 - Resume interrupted download (-c): Very useful for large files. If the connection drops, wget continues where it left off instead of starting over.
Bash
wget -c http://example.com/very-large-iso-image.iso - Mirror entire website (Recursive): Downloads a page including all linked resources (be cautious with large sites!).
Bash
wget -r -np -k http://example.com/documentation/
curl (Client URL)
`curl` supports far more protocols than `wget` and, by default, outputs file contents to the console (stdout), making it perfect for piping (`|`).
curl [Optionen] [URL]- Save file (-o or -O): -O (uppercase) retains the original name, -o (lowercase) allows renaming.
Bash
curl -O http://example.com/image.jpg curl -o my_image.jpg http://example.com/image.jpg - Display header information (-I): Shows only the HTTP header (e.g., server type, status code 200/404, caching rules) without downloading the file.
Bash
curl -I google.com - Send data to an API (POST request): Commonly used to test REST APIs or send JSON data.
Bash
curl -X POST -d "param1=value1¶m2=value2" http://example.com/api/login
11. Monitoring & Analysis: iftop & tcpdump
When the network is slow or suspicious traffic appears, these tools are the first port of call for analysis.
iftop
iftop does for network usage what top does for CPU usage. It displays in real time who is communicating with whom and how much bandwidth is being consumed.
iftop [Optionen]- Standard start: Requires sudo to access the interface. Displays bar charts of current connections.
Bash
sudo iftop - Select specific interface (-i): When a server has multiple network cards (e.g., eth0 for LAN, eth1 for WAN).
Bash
sudo iftop -i eth1 - Disable DNS resolution (-n): Speeds up display by skipping hostname resolution (shows IPs only).
Bash
sudo iftop -n
tcpdump
The ultimate tool for in-depth analysis. It captures raw data packets. Since the terminal output is often too fast, the data is usually saved for later analysis.
tcpdump [Optionen] [Filter]- Display traffic on port 80 (HTTP):Bash
sudo tcpdump port 80 - Write to file for Wireshark (-w):This is the professional workflow: capture packets on the server (.pcap file) and then analyze locally using Wireshark’s GUI.Bash
sudo tcpdump -w capture.pcap port 443 - Complex filter:Shows only traffic from a specific IP (192.168.1.5) AND a specific port (22).Bash
sudo tcpdump src 192.168.1.5 and port 22
12. whois
`whois` is a query tool for registrar databases (such as DENIC or GoDaddy). It helps determine who owns a domain or IP address.
whois [Abfrage]- Domain information: Displays registration date, name servers, and (if not protected by GDPR) the owner's contact details. Bash
whois google.com - Determine IP owner: Finds out which ISP or company an IP address belongs to. Very useful for tracing attacker IPs in log files. Bash
whois 8.8.8.8
Cheat Sheet: Legacy (net-tools) vs. Modern (iproute2)
Since many online guides still use the old commands, here’s a quick reference table for modern Linux daily use.
| Task | Legacy (Deprecated) | Modern (Recommended) |
| Show interface | ifconfig | ip addr show |
| Enable interface | ifconfig eth0 up | ip link set eth0 up |
| Add IP address | ifconfig eth0 192.168.1.2 | ip addr add 192.168.1.2/24 dev eth0 |
| Routing table | route -n | ip route |
| Add route | route add default gw ... | ip route add default via ... |
| Display ARP cache | arp -n | ip neigh |
| Display connections | netstat | ss |
| Check open ports | netstat -tulpn | ss -tulpn |