Skip to content

Network

SSH (Secure Shell)

  • Login to a remote server:

    ssh username@remote_host
    
  • Connect to a remote server on a specific port:

    ssh -p port_number username@remote_host
    
  • Run a command on a remote server:

    ssh username@remote_host command_to_run
    
  • Use an SSH key for authentication:

    ssh -i /path/to/private_key username@remote_host
    
  • SSH Tunneling (Local Port Forwarding):

    ssh -L local_port:destination_host:destination_port username@remote_host
    
  • SSH Reverse Port Forwarding:

    ssh -R remote_port:destination_host:destination_port username@remote_host
    
  • Copy SSH public key to server (Password-less SSH):

    ssh-copy-id username@remote_host
    

SCP (Secure Copy Protocol)

  • Copy file from local to remote:

    scp /path/to/local_file username@remote_host:/path/to/remote_dir
    
  • Copy file from remote to local:

    scp username@remote_host:/path/to/remote_file /path/to/local_dir
    
  • Copy directory recursively:

    scp -r /path/to/local_dir username@remote_host:/path/to/remote_dir
    

File Transfer with Rsync

  • Sync files from local to remote:

    rsync -avz /path/to/local_dir username@remote_host:/path/to/remote_dir
    
  • Sync files from remote to local:

    rsync -avz username@remote_host:/path/to/remote_dir /path/to/local_dir
    
  • Delete files from the destination that don’t exist on the source:

    rsync -avz --delete /path/to/source_dir username@remote_host:/path/to/destination_dir
    

Network Tools

  • Check network connectivity (Ping):

    ping remote_host
    
  • Trace route to a host:

    traceroute remote_host
    
  • Display network interfaces and IP addresses: or

    ip addr
    
    ifconfig
    
  • Check open ports on a remote host:

    nmap remote_host
    
  • Check currently established connections: or

    netstat -an
    
    ss -tuln
    

File and Process Operations

  • View open files used by a process:

    lsof -p process_id
    
  • Kill a process by its name:

    pkill process_name
    
  • Kill a process by its PID:

    kill -9 process_id
    

Networking & Monitoring

  • Monitor traffic on an interface:

    tcpdump -i interface
    
  • Check bandwidth usage:

    iftop -i interface
    
  • Query DNS for a domain:

    nslookup domain_name
    
  • Perform a more detailed DNS query:

    dig domain_name
    

Firewall Configuration (ufw)

  • Enable UFW (Uncomplicated Firewall):

    sudo ufw enable
    
  • Allow a specific port:

    sudo ufw allow port_number
    
  • Check UFW status:

    sudo ufw status
    

Network Configuration

  • Change hostname:

    sudo hostnamectl set-hostname new_hostname
    
  • View routing table:

    ip route
    
  • Add a static route:

    ip route add destination_network via gateway_ip dev interface
    

Other Useful Commands

  • Speedtest CLI (Check internet speed):

    speedtest-cli
    
  • Download file from the web: or

    wget file_url
    
    curl -O file_url
    
  • Test the reachability of a specific port:

    nc -zv remote_host port_number