Introduction to common network protocols
when computers communicate over a network, they follow specific rules called protocols. each protocol is designed for a particular purpose, such as loading websites, transferring files, or remotely controlling another computer.
think of a protocol as a language with strict rules. if both sides follow the same rules, communication works correctly.
Below is a beginner-friendly explanation of some of the most common protocols used on the internet.
1. https (hypertext transfer protocol secure)
https is the secure version of http. it is used for loading websites securely.
when you visit a website like:
your browser and the web server communicate using https.
how https works:
- your browser connects to the server (usually on port 443).
- they perform a secure handshake.
- the server sends a digital certificate.
- encryption is established.
- data is exchanged securely.
https uses:
- Hypertext Transfer Protocol (http)
- Transport Layer Security (tls)
why https is important:
- encrypts data
- prevents attackers from reading information
- protects passwords and credit card data
example using python to make an https request:
import requests
response = requests.get("https://example.com")
print(response.status_code)
print(response.text[:200])
2. ftp (file transfer protocol)
ftp is used to transfer files between computers over a network.
it typically uses:
- port 21 (control connection)
- port 20 (data connection)
ftp is not secure by default because it sends data in plain text.
common uses:
- uploading website files to a server
- downloading files from remote servers
secure alternatives:
- ftps (ftp over tls)
- sftp (ssh file transfer protocol)
example ftp connection in python:
from ftplib import FTP
ftp = FTP("ftp.example.com")
ftp.login(user="username", passwd="password")
ftp.retrlines("LIST")
ftp.quit()
3. ssh (secure shell)
ssh allows you to remotely access and control another computer securely.
it usually runs on port 22.
what ssh does:
- encrypts communication
- allows remote command execution
- supports secure file transfers (sftp)
example use case:
you connect from your laptop to a remote linux server:
ssh user@server_ip
behind the scenes, ssh:
- establishes a secure encrypted channel
- authenticates the user
- allows command execution
ssh uses strong encryption to prevent eavesdropping.
example using python (paramiko library):
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("example.com", username="user", password="password")
stdin, stdout, stderr = ssh.exec_command("ls")
print(stdout.read().decode())
ssh.close()
4. smtp
smtp is used to send emails between mail servers.
it usually runs on:
- port 25 (standard)
- port 587 (secure submission)
smtp handles sending emails, not receiving them.
example sending email with python:
import smtplib
server = smtplib.SMTP("smtp.example.com", 587)
server.starttls()
server.login("user@example.com", "password")
message = "Subject: Test\n\nThis is a test email."
server.sendmail("user@example.com", "recipient@example.com", message)
server.quit()
5. pop3 and imap
these protocols are used to receive emails.
pop3 (post office protocol version 3):
- downloads emails to your device
- usually removes them from the server
- port 110 (or 995 secure)
imap (internet message access protocol):
- keeps emails on the server
- syncs across devices
- port 143 (or 993 secure)
imap is more modern and commonly used today.
6. dns (domain name system)
dns translates domain names into ip addresses.
example:
when you type:
google.com
dns translates it into something like:
142.250.190.14
dns usually uses:
- port 53
- udp (sometimes tcp)
without dns, you would have to remember numeric ip addresses for every website.
7. dhcp (dynamic host configuration protocol)
dhcp automatically assigns ip addresses to devices on a network.
when you connect to wifi:
- your device sends a request.
- the dhcp server assigns an ip address.
- it also provides gateway and dns information.
dhcp usually uses:
- port 67 (server)
- port 68 (client)
- udp
summary of common protocols
https:
- secure web browsing
- port 443
- encrypted
ftp:
- file transfer
- port 21
- not secure by default
ssh:
- secure remote login
- port 22
- encrypted
smtp:
- sending email
- port 25/587
pop3:
- download email
- port 110
imap:
- sync email
- port 143
dns:
- domain name translation
- port 53
- usually udp
dhcp:
- automatic ip assignment
- ports 67/68
- udp
How these protocols work together
when you open a website:
- dhcp gives your device an ip address.
- dns translates the website name to an ip.
- your browser connects using https.
- tcp ensures reliable data transfer.
- tls encrypts the communication.
each protocol has a specific role, and together they make the internet function smoothly.
# =========================
# https request example
# =========================
import requests
def https_example():
response = requests.get("https://example.com")
print(response.status_code)
print(response.text[:200])
# =========================
# ftp example
# =========================
from ftplib import FTP
def ftp_example():
ftp = FTP("ftp.example.com")
ftp.login(user="username", passwd="password")
ftp.retrlines("LIST")
ftp.quit()
# =========================
# ssh example
# =========================
import paramiko
def ssh_example():
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("example.com", username="user", password="password")
stdin, stdout, stderr = ssh.exec_command("ls")
print(stdout.read().decode())
ssh.close()
# =========================
# smtp example
# =========================
import smtplib
def smtp_example():
server = smtplib.SMTP("smtp.example.com", 587)
server.starttls()
server.login("user@example.com", "password")
message = "Subject: Test\n\nThis is a test email."
server.sendmail("user@example.com", "recipient@example.com", message)
server.quit()
# choose which function to run manually
# https_example()
# ftp_example()
# ssh_example()
# smtp_example()