Skip to content

atulkamble/linux-networking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

📖 Linux Networking Commands — With Practice Codes


🔍 1️⃣ View IP Address Information

ip addr show

or

ifconfig   # (Older systems)

Practice: Check your active interfaces and IPs:

ip addr show | grep inet

📡 2️⃣ Test Network Connectivity (Ping)

ping google.com

Practice: Ping a specific server for 5 packets:

ping -c 5 8.8.8.8

🌐 3️⃣ Display Routing Table

ip route show

or

route -n

Practice: Check your default gateway:

ip route | grep default

🔌 4️⃣ Check Open Ports and Listening Services

netstat -tuln

or

ss -tuln

Practice: List all TCP connections:

ss -tn

🕵️‍♂️ 5️⃣ DNS Lookup

nslookup google.com

or

dig google.com

Practice: Get the A record of a domain:

dig +short google.com

📞 6️⃣ Trace Network Route

traceroute google.com

Practice: Trace path to Cloudflare DNS:

traceroute 1.1.1.1

🌍 7️⃣ Download Files via Command Line

curl -O http://example.com/file.zip

or

wget http://example.com/file.zip

Practice: Download a webpage source:

curl https://example.com

📊 8️⃣ Network Bandwidth Usage

Install:

sudo yum install -y iperf3

Start a server (on one terminal):

iperf3 -s

Run client (on another terminal/server):

iperf3 -c <server-ip>

📥 9️⃣ Check Public IP Address

curl ifconfig.me

or

curl ipinfo.io/ip

🗃️ 🔒 10️⃣ Add/Delete Firewall Rules (Firewalld Example)

Check firewalld status:

sudo systemctl status firewalld

Open HTTP port:

sudo firewall-cmd --add-port=80/tcp --permanent
sudo firewall-cmd --reload

📡 11️⃣ Enable/Disable Network Interface

Disable eth0:

sudo ip link set eth0 down

Enable eth0:

sudo ip link set eth0 up

📥 12️⃣ Transfer Files Between Servers (scp)

scp file.txt user@192.168.1.20:/home/user/

Practice: Transfer a local file to a remote server's /tmp/ directory:

scp /etc/hosts user@<remote-ip>:/tmp/

📦 Bonus: Create a Simple Networking Script

A bash script to check if a list of hosts is reachable:

Create ping_hosts.sh

#!/bin/bash
for ip in "8.8.8.8" "1.1.1.1" "google.com"
do
  ping -c 2 $ip &> /dev/null
  if [ $? -eq 0 ]; then
    echo "$ip is reachable"
  else
    echo "$ip is NOT reachable"
  fi
done

Run it

bash ping_hosts.sh

About

Linux Networking

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors