Linux Advanced β Networking Practice Exercises
Practice Exercises
Exercise 1 β Network Discovery
Find your machineβs IP address, default gateway, and DNS servers using command-line tools.
π‘ Show Answer
# IP address
ip -br addr
# or
hostname -I
# Default gateway
ip route | grep default
# default via 192.168.1.1 dev eth0
# DNS servers
cat /etc/resolv.conf
# nameserver 8.8.8.8
# nameserver 8.8.4.4
# All in one:
echo "IP: $(hostname -I | awk '{print $1}')"
echo "Gateway: $(ip route | awk '/default/ {print $3}')"
echo "DNS: $(grep nameserver /etc/resolv.conf | awk '{print $2}' | tr '\n' ' ')"
Exercise 2 β Port Investigation
Find all services listening on TCP ports, then check specifically if anything is running on ports 22, 80, and 443.
π‘ Show Answer
# All listening TCP ports
sudo ss -tlnp
# Check specific ports
for port in 22 80 443; do
result=$(sudo ss -tlnp | grep ":$port ")
if [ -n "$result" ]; then
echo "Port $port: OPEN"
echo " $result"
else
echo "Port $port: CLOSED"
fi
done
Exercise 3 β DNS Investigation
For the domain github.com, find its A record, MX records, and name servers. Then do a reverse lookup on one of its IP addresses.
π‘ Show Answer
# A record (IPv4)
dig +short github.com
# 140.82.121.3
# MX records
dig +short github.com MX
# 1 aspmx.l.google.com.
# ...
# Name servers
dig +short github.com NS
# dns1.p08.nsone.net.
# ...
# Reverse lookup
dig -x 140.82.121.3
# 3.121.82.140.in-addr.arpa. ... PTR lb-140-82-121-3-iad.github.com.
Exercise 4 β SSH Key Setup
Generate an Ed25519 SSH key pair and create an SSH config entry for a server called myserver at 192.168.1.50 with user deploy on port 2222.
π‘ Show Answer
# Generate key pair
ssh-keygen -t ed25519 -C "deploy-key" -f ~/.ssh/deploy_key
# Create SSH config entry
cat >> ~/.ssh/config << 'EOF'
Host myserver
HostName 192.168.1.50
User deploy
Port 2222
IdentityFile ~/.ssh/deploy_key
EOF
# Set correct permissions
chmod 600 ~/.ssh/config
chmod 600 ~/.ssh/deploy_key
# Copy key to server (when server is reachable)
# ssh-copy-id -i ~/.ssh/deploy_key myserver
# Now connect with just:
# ssh myserver
Exercise 5 β File Transfer Challenge
Download a file from https://example.com/data.csv, then transfer it to a remote server at 192.168.1.10:/tmp/ using two different methods. Show how to verify the transfer.
π‘ Show Answer
# Download the file
curl -O https://example.com/data.csv
# or
wget https://example.com/data.csv
# Method 1: scp
scp data.csv user@192.168.1.10:/tmp/
# Method 2: rsync (better for large files)
rsync -avz data.csv user@192.168.1.10:/tmp/
# Verify β check file exists and size matches
# Local:
ls -l data.csv
md5sum data.csv
# Remote:
ssh user@192.168.1.10 'ls -l /tmp/data.csv && md5sum /tmp/data.csv'
| β Back to SSH & DNS | π Back to Linux Advanced |