OS: Linux Networking Basics

Networking is a vital part of Linux system administration. Whether you’re troubleshooting connectivity issues or configuring servers, you’ll often need to check network connections.

 `ping` – Test Connectivity

The ping command checks whether your system can reach another host (computer, server, or website).

  • Example:
  • bash
    ping google.com

This sends ICMP echo requests and shows replies, verifying network connectivity.

  • Stop ping:
  • Press CTRL + C.

  • Use -c to limit the number of packets:
  • bash
    ping -c 4 8.8.8.8


`ifconfig` – Network Interface Information (Legacy)

ifconfig (from the net-tools package) shows and configures network interfaces. It’s considered deprecated, but still found on some systems.

  • Show all interfaces:
  • bash
    ifconfig

  • Bring an interface up or down:
  • bash
    sudo ifconfig eth0 up
    sudo ifconfig eth0 down


 `ip` – Modern Networking Tool

The ip command (from the iproute2 package) is the modern replacement for ifconfig.

  • Show IP addresses:
  • bash
    ip addr

  • Show network interfaces:
  • bash
    ip link

  • Show routing table:
  • bash
    ip route

  • Assign an IP address:
  • bash
    sudo ip addr add 192.168.1.100/24 dev eth0


File Transfer (scp, rsync, wget, curl)

Linux provides several tools to copy files locally, transfer them across systems, and download from the internet. Each tool has its strengths.

`scp` – Secure Copy

scp copies files between local and remote systems over SSH.

  • Copy from local to remote:
  • bash
    scp file.txt user@server:/home/user/

  • Copy from remote to local:
  • bash
    scp user@server:/home/user/file.txt .

  • Copy a directory (recursive):
  • bash
    scp -r project/ user@server:/home/user/


 `rsync` – Efficient File Synchronization

rsync is more powerful than scp — it syncs files, only transferring changes.

  • Copy local to remote:
  • bash
    rsync -avz project/ user@server:/home/user/project/

  • Copy remote to local:
  • bash
    rsync -avz user@server:/home/user/project/ ./project/

  • Key features:
  • a → archive (preserve permissions, symlinks).
  • v → verbose.
  • z → compression.
  • Can resume interrupted transfers.

 `wget` – Download from the Web

wget is a command-line downloader.

  • Download a file:
  • bash
    wget https://example.com/file.zip

  • Resume a partial download:
  • bash
    wget -c https://example.com/file.zip

  • Download an entire website (mirroring):
  • bash
    wget -r -np -k https://example.com


 `curl` – Transfer Data with URLs

curl is a versatile tool for fetching or sending data across protocols (HTTP, FTP, etc.).

  • Download a file:
  • bash
    curl -O https://example.com/file.zip

  • Save output to a custom file:
  • bash
    curl -o myfile.zip https://example.com/file.zip

  • Test a website response:
  • bash
    curl -I https://example.com

  • Send POST data:
  • bash
    curl -d "user=amr&pass=1234" https://example.com/login


  • scp → secure file copy via SSH.
  • rsync → sync directories efficiently.
  • wget → simple web downloader.
  • curl → advanced tool for HTTP/FTP requests and APIs.

SSH Basics (Secure Shell)

SSH (Secure Shell) is the standard way to securely connect to remote Linux systems over a network. It provides encrypted communication for running commands, transferring files, and managing servers.

What is SSH?

  • protocol for secure remote login and command execution.
  • Replaces insecure tools like telnet and rlogin.
  • Uses port 22 by default.
  • Provides authentication via passwords or SSH keys.

Connecting to a Remote Server

Basic syntax:

bash
ssh user@hostname

  • user → the username on the remote system.
  • hostname → IP address or domain of the server.

Example:

bash
ssh amr@192.168.1.50


SSH keys provide secure, passwordless authentication.

  1. Generate a key pair:
  2. bash
    ssh-keygen -t rsa -b 4096

  1. Copy public key to server:
  2. bash
    ssh-copy-id user@hostname

  1. Connect without a password:
  2. bash
    ssh user@hostname


Common SSH Options

  • Specify a custom port:
  • bash
    ssh -p 2222 user@hostname

  • Run a single command remotely:
  • bash
    ssh user@hostname "ls -l /var/log"

  • Use a config file (~/.ssh/config) for shortcuts:
  • bash
    Host myserver
        HostName 192.168.1.50
        User amr
        Port 22

Then connect with:

bash
ssh myserver