// 04 — NETWORKING

🌐 NETWORKING

Networking reference — TCP/IP model, subnetting, common protocols, SNMP and diagnostic tools.

TCP/IP Subnetting SNMP Protocols Diagnostics

// TCP/IP Model

// LAYER 4 — APPLICATION

Where user-facing protocols live. HTTP, HTTPS, FTP, SSH, DNS, SMTP, SNMP. Data is formatted and presented to the user here.

// LAYER 3 — TRANSPORT

TCP — reliable, ordered, connection-based. UDP — fast, connectionless, no guarantee. Ports live at this layer.

// LAYER 2 — INTERNET

IP addressing and routing. IPv4, IPv6, ICMP, ARP. Responsible for logical addressing and path selection between networks.

// LAYER 1 — NETWORK ACCESS

Physical transmission. Ethernet, Wi-Fi, MAC addresses. Deals with how bits are sent over the physical medium.

TCP/IP LAYEROSI EQUIVALENTKEY PROTOCOLSUNIT
ApplicationApplication / Presentation / SessionHTTP, DNS, FTP, SMTP, SNMP, SSHData
TransportTransportTCP, UDPSegment / Datagram
InternetNetworkIP, ICMP, ARP, OSPF, BGPPacket
Network AccessData Link / PhysicalEthernet, Wi-Fi, PPPFrame / Bit
💡

TCP vs UDP: TCP guarantees delivery with a 3-way handshake (SYN → SYN-ACK → ACK). UDP just fires packets — faster but no delivery confirmation. Use TCP for reliability, UDP for speed (video, DNS, SNMP).

// Common Protocols

PROTOCOLPORTTRANSPORTDESCRIPTION
HTTP80TCPWeb traffic, unencrypted
HTTPS443TCPWeb traffic, TLS encrypted
FTP20/21TCPFile transfer (unencrypted)
SFTP22TCPSecure file transfer over SSH
SSH22TCPEncrypted remote shell access
Telnet23TCPRemote shell, unencrypted — avoid
SMTP25 / 587TCPEmail sending
DNS53UDP / TCPDomain name resolution
DHCP67/68UDPAutomatic IP assignment
SNMP161/162UDPNetwork device monitoring
LDAP389TCPDirectory services
RDP3389TCPWindows remote desktop
NTP123UDPTime synchronisation
ICMPIPPing, traceroute, error messages

// Subnetting

// CIDR NOTATION

A subnet mask written as a prefix length. /24 means 24 bits for the network, 8 bits for hosts → 256 addresses (254 usable).

// PRIVATE RANGES

10.0.0.0/8 — Class A (16M hosts)
172.16.0.0/12 — Class B (1M hosts)
192.168.0.0/16 — Class C (65K hosts)

// SPECIAL ADDRESSES

127.0.0.1 — loopback (localhost)
0.0.0.0 — all interfaces
255.255.255.255 — broadcast
x.x.x.0 — network address
x.x.x.255 — broadcast address

CIDRSUBNET MASKHOSTSEXAMPLE
/8255.0.0.016,777,21410.0.0.0/8
/16255.255.0.065,534192.168.0.0/16
/24255.255.255.0254192.168.1.0/24
/25255.255.255.128126192.168.1.0/25
/26255.255.255.19262192.168.1.0/26
/27255.255.255.22430192.168.1.0/27
/28255.255.255.24014192.168.1.0/28
/30255.255.255.2522192.168.1.0/30
/32255.255.255.2551Single host

// SNMP — Simple Network Management Protocol

// WHAT IS SNMP

SNMP is a protocol for monitoring and managing network devices — routers, switches, servers, printers. It runs over UDP port 161 (queries) and 162 (traps).

// HOW IT WORKS

A manager (your monitoring system) queries agents (devices) for data stored in a MIB (Management Information Base) — a tree of OIDs (Object Identifiers).

// SNMP VERSIONS

v1 — original, community string auth, insecure
v2c — faster, still community string
v3 — authentication + encryption, use this in production

// COMMUNITY STRINGS

Used in v1/v2c as a password. Default is often public (read) or private (write). Always change defaults — these are frequently exploited.

OPERATIONDIRECTIONDESCRIPTION
GETManager → AgentRetrieve a specific OID value
GET-NEXTManager → AgentRetrieve the next OID in the MIB tree
GET-BULKManager → AgentRetrieve large blocks of data (v2c+)
SETManager → AgentWrite a value to the agent
RESPONSEAgent → ManagerReply to GET/SET requests
TRAPAgent → ManagerUnsolicited alert sent by agent (port 162)
INFORMAgent → ManagerAcknowledged trap (v2c+)
WALKManager → AgentTraverse entire MIB subtree
⚠️

Security note: SNMPv1 and v2c send community strings in plain text. Never expose SNMP to the internet. Use SNMPv3 with authPriv security level for production environments.

// SNMP Commands

💡

Install SNMP tools on Linux: apt install snmp snmpd snmp-mibs-downloader

BASH — snmpwalk
# Walk entire MIB tree (v2c)
snmpwalk -v2c -c public 192.168.1.1

# Walk specific OID subtree
snmpwalk -v2c -c public 192.168.1.1 system
snmpwalk -v2c -c public 192.168.1.1 interfaces
snmpwalk -v2c -c public 192.168.1.1 1.3.6.1.2.1.1

# Walk with SNMPv3
snmpwalk -v3 -l authPriv -u admin -a SHA -A authpass -x AES -X privpass 192.168.1.1
BASH — snmpget
# Get system description
snmpget -v2c -c public 192.168.1.1 sysDescr.0

# Get system uptime
snmpget -v2c -c public 192.168.1.1 sysUpTime.0

# Get hostname
snmpget -v2c -c public 192.168.1.1 sysName.0

# Get interface speed by OID
snmpget -v2c -c public 192.168.1.1 1.3.6.1.2.1.2.2.1.5.1
BASH — snmpset & other tools
# Set a value (requires write community)
snmpset -v2c -c private 192.168.1.1 sysName.0 s "NewHostname"

# Bulk walk (faster than snmpwalk)
snmpbulkwalk -v2c -c public 192.168.1.1 interfaces

# Test SNMP connectivity
snmpstatus -v2c -c public 192.168.1.1

# Translate OID to human-readable
snmptranslate 1.3.6.1.2.1.1.1.0
snmptranslate -On sysDescr.0      # reverse: name to OID
USEFUL OIDNAMEDESCRIPTION
1.3.6.1.2.1.1.1.0sysDescrSystem description / OS info
1.3.6.1.2.1.1.3.0sysUpTimeSystem uptime in timeticks
1.3.6.1.2.1.1.5.0sysNameHostname of the device
1.3.6.1.2.1.1.6.0sysLocationPhysical location string
1.3.6.1.2.1.2.1.0ifNumberNumber of network interfaces
1.3.6.1.2.1.2.2.1.2ifDescrInterface name (eth0, etc.)
1.3.6.1.2.1.2.2.1.10ifInOctetsBytes received on interface
1.3.6.1.2.1.2.2.1.16ifOutOctetsBytes sent on interface
1.3.6.1.4.1enterprisesVendor-specific MIBs

// Diagnostic Tools

BASH
# Ping & reachability
ping -c 4 8.8.8.8               # 4 ICMP echo requests
ping -i 0.2 -c 10 192.168.1.1  # fast ping every 0.2s
ping6 ::1                       # ping IPv6 loopback

# Traceroute
traceroute 8.8.8.8             # trace path to host
traceroute -n 8.8.8.8          # no DNS resolution (faster)
mtr 8.8.8.8                    # live traceroute + ping combined
mtr --report 8.8.8.8          # generate report and exit

# DNS diagnostics
dig google.com                 # full DNS query
dig google.com A              # A record only
dig google.com MX             # mail records
dig google.com NS             # nameserver records
dig +short google.com        # short answer only
dig @8.8.8.8 google.com      # query specific DNS server
nslookup google.com           # simple DNS lookup

# Port & connection checking
nc -zv 192.168.1.1 80         # test if port is open (netcat)
nc -zv 192.168.1.1 20-25     # test port range
telnet 192.168.1.1 80         # manual port test
curl -v https://example.com   # full HTTP request with headers

# Packet capture
tcpdump -i eth0               # capture on interface
tcpdump -i eth0 port 80      # filter by port
tcpdump -i eth0 host 8.8.8.8 # filter by host
tcpdump -w capture.pcap      # save to file (open in Wireshark)
tcpdump -r capture.pcap      # read saved capture

// Firewall — iptables & ufw

BASH — ufw (simple)
ufw status                    # show firewall status
ufw enable                    # enable firewall
ufw disable                   # disable firewall
ufw allow 22                  # allow SSH
ufw allow 80/tcp             # allow HTTP
ufw allow from 192.168.1.0/24 # allow entire subnet
ufw deny 23                   # block Telnet
ufw delete allow 80          # remove a rule
ufw reset                     # reset all rules
BASH — iptables (advanced)
iptables -L -n -v            # list all rules verbose
iptables -A INPUT -p tcp --dport 22 -j ACCEPT   # allow SSH in
iptables -A INPUT -p tcp --dport 80 -j ACCEPT   # allow HTTP in
iptables -A INPUT -j DROP   # drop all other inbound
iptables -D INPUT 1         # delete rule 1 from INPUT chain
iptables -F                  # flush (clear) all rules
iptables-save                 # save current rules
iptables-restore              # restore saved rules
🚨

Warning: Dropping all INPUT traffic with iptables before allowing SSH will lock you out of a remote server. Always add your allow rules before a default DROP.

// Common Ports Reference

PORTPROTOCOLSERVICENOTES
20/21TCPFTPData / control — unencrypted
22TCPSSH / SFTPEncrypted remote access
23TCPTelnetUnencrypted — avoid
25TCPSMTPEmail relay
53UDP/TCPDNSUDP for queries, TCP for zone transfers
67/68UDPDHCPServer/client
80TCPHTTPUnencrypted web
110TCPPOP3Email retrieval
123UDPNTPTime sync
143TCPIMAPEmail retrieval
161/162UDPSNMPQueries / traps
389TCPLDAPDirectory services
443TCPHTTPSTLS encrypted web
445TCPSMBWindows file sharing
3306TCPMySQLDatabase
3389TCPRDPWindows remote desktop
5432TCPPostgreSQLDatabase
6379TCPRedisIn-memory data store
8080TCPHTTP-altCommon dev/proxy port
8443TCPHTTPS-altAlternative HTTPS