VIM Editor & Networking Basics
VIM Editor & Networking Basics
Vim (short for "Vi IMproved") is a highly configurable and powerful text editor that is designed for
efficient text editing. It is an advanced version of the older Unix text editor called "vi." Vim is known for
its modal editing system, which allows users to perform various tasks by switching between different
modes.
Networking Basics
Imagine your computer is like a house, and you want to communicate with other houses in your
neighborhood. To do this, you need a network. In the Linux world, a network is like a bunch of houses
(computers) that can talk to each other and share things, like information and files.
• Router: Think of the router as the neighborhood's central hub. It helps all the houses
(computers) in the network communicate with each other and with the outside world, like the
internet. It's like the mail center that forwards messages between houses.
• Sending and Receiving Data: When you want to send a message to another computer, your
computer packages the message and puts an address on it (the IP address of the receiving
computer). The router helps the message find its way to the right destination. When the
message reaches the other computer, it opens the package and reads the message.
5. Firewall: Just like you might have a fence around your house for security, Linux has a firewall to
protect your computer from unwanted stuff coming in from the network. It decides which messages are
allowed to enter your computer and which should be blocked.
6. Wired and Wireless: Just as you can connect to the internet using a cable or Wi-Fi at home, your
Linux computer can connect using Ethernet cables (wired) or Wi-Fi signals (wireless).
7. Network Services: Think of network services as different types of shops in the neighborhood.
Some computers might be running a service to share files, while others might offer web pages. These
services make the network more useful.
8. DNS: When you type a website address in your browser, your computer needs to know the IP
address of that website. DNS (Domain Name System) is like a phone book that translates the website
address into an IP address so your computer can find it on the network.
So, in a nutshell, networking in Linux is all about computers talking to each other, sharing information,
and working together like neighbors in a community. It's what lets your computer connect to the
internet, access files on other computers, and do so much more!
LAN
A LAN is a network of interconnected devices within a limited geographic area, such as a home, office
building, or campus. LANs are used to facilitate communication and data sharing between devices that
are in close proximity to each other.
In a Local Area Network (LAN), a switch is a networking device that plays a crucial role in connecting and
managing the communication between devices within the LAN. Switches operate at the data link layer
(Layer 2) of the OSI (Open Systems Interconnection) model and are essential for creating efficient and
reliable LAN environments
An IP address (Internet Protocol address) is like a unique home address for devices on a
network, allowing them to find and communicate with each other. It's made up of numbers
separated by dots, such as 192.168.1.1. Here are examples to explain different aspects:
1. IPv4 Addressing:
• Example: 192.168.0.10
• Think of it like a street address for your computer on the internet or local
network. Each number (0-255) identifies a part of the address hierarchy.
2. Subnet Mask:
• Example: 255.255.255.0
• It's like a fence that divides your big address space into smaller parts. It helps
devices know which addresses are in the same "neighborhood."
3. Default Gateway:
• Example: 192.168.0.1
• This is like the main entrance to your neighborhood. When your device wants to
talk to devices in other neighborhoods (outside your local network), it goes
through this gateway.
4. DNS Address:
• Example: 8.8.8.8
• It's like the phonebook of the internet. Converts domain names (like
www.example.com) to IP addresses. DNS helps your device find websites.
Remember, IP addresses help devices communicate by uniquely identifying them, just like
addresses do for houses.
An IP address consists of four octets (8-bit groups) represented in binary form. Each octet
represents a portion of the IP address, ranging from 0 to 255 in decimal. Understanding IP
addresses in binary octets can help illustrate how computers identify and communicate with
each other on networks. Let's break down an example IP address into its binary octets:
1. Convert to Binary:
• 192 in binary: 11000000
• 168 in binary: 10101000
• 1 in binary: 00000001
• 10 in binary: 00001010
2. Representing in Octets:
• First Octet (192): 11000000
• Second Octet (168): 10101000
• Third Octet (1): 00000001
• Fourth Octet (10): 00001010
This IP address, 192.168.1.10, can be broken down into its binary octets like this:
Each octet represents a portion of the address, and the dots separate the octets. Computers
use these binary patterns to route data within networks.
In this example, the binary pattern helps routers and devices know how to direct data packets
to the correct destination. It's like the postal code of a house, where each digit specifies a part
of the route for the package.
Router: A router is a networking device that connects different networks together and directs traffic
between them. It's like a traffic cop that decides where data should go within a network and beyond. In a
home or office network, the router acts as a central hub that allows devices to communicate with each other
and with the internet.
Example: Imagine your home network. Your router has an IP address that serves as its identity within the
network. Let's say your router's IP address is 192.168.1.1. It's like the main entrance to your home's network,
handling data traffic between devices in your home and the larger internet.
Gateway IP Address: A gateway IP address is the address of a device on a network that serves as an entry
and exit point to another network. It's usually associated with the router that connects your local network to
the internet or another external network.
Example: Continuing from the previous example, your router's IP address (192.168.1.1) is also the gateway IP
address for devices within your home network. When a device wants to access resources outside your home
network, like a website on the internet, it sends data through the gateway (your router), which then forwards
the data to its intended destination and brings back the response.
In summary, the router is the device that manages traffic within your local network and also serves as the
gateway to connect your local network to the larger internet or another external network. The gateway IP
address is the IP address of this router, which serves as the entry and exit point for data traveling between
your local network and external networks.
SUBNETS:
The subnet concept is a fundamental aspect of networking that involves dividing a larger IP network into
smaller, manageable segments. Subnetting is used to efficiently allocate IP addresses, manage network
traffic, and improve security. Let's explore this concept in more detail:
1. IP Address Structure: An IP address consists of two parts: the network portion and the host portion.
Subnetting focuses on dividing the IP address space into these two segments.
2. Subnet Mask: A subnet mask is a 32-bit value that separates the network portion and the host portion of
an IP address. It uses a combination of 1s and 0s to indicate which bits represent the network and host
portions. The subnet mask is typically written in decimal-dotted format, like 255.255.255.0.
3. Why Subnet? Subnetting allows you to create smaller networks within a larger network. This has several
benefits:
• Efficient IP address allocation: You can assign IP addresses based on specific needs within each
subnet.
• Improved network performance: Smaller subnets mean less broadcast traffic and more efficient
routing.
• Enhanced security: Subnets can be isolated from each other, providing better control over network
access.
4. Subnet Calculation: To create subnets, you borrow bits from the host portion of an IP address to form the
subnet portion. The number of borrowed bits determines the number of subnets and hosts per subnet you
can have.
5. Subnetting Example: Let's consider the IP address 192.168.1.0 with a subnet mask of 255.255.255.0
(which represents a /24 subnet). By borrowing a few host bits, you can create subnets like this:
6. CIDR Notation: CIDR (Classless Inter-Domain Routing) notation is used to represent IP addresses and
subnet masks more efficiently. It uses a prefix length to indicate the number of bits in the subnet mask. For
example, the /24 subnet mask can be represented as 192.168.1.0/24.
7. VLSM: Variable Length Subnet Masking (VLSM) is a technique where different subnets can have different
subnet mask lengths. This allows for more efficient utilization of IP address space.
In summary, subnetting is the process of dividing a larger IP network into smaller subnetworks, enabling
efficient IP address management, improved network performance, and better security. It involves using
subnet masks and CIDR notation to define the boundaries of these subnetworks. Subnetting is a crucial skill
for network administrators and engineers to design and maintain efficient and scalable networks.
Let's dive deeper into subnetting, subnet masks, CIDR, and subnetting with detailed examples:
2. Subnet Mask: A subnet mask is a 32-bit value that separates the network portion and the
host portion of an IP address. It uses binary bits to indicate which parts of the IP address belong
to the network and which parts belong to individual hosts within that network.
4. Subnetting Example: Let's consider the IP address range "192.168.0.0" with a default subnet
mask of "255.255.255.0" (or /24 in CIDR notation). We'll divide this network into smaller
subnets.
Step 1: Start with the default subnet mask (24 bits) and identify how many subnets and hosts
per subnet are needed. Let's say we need 4 subnets and each subnet should accommodate 30
hosts.
Step 2: Determine the number of bits needed for the subnet portion of the IP address.
Calculate this using the formula: 2^n >= Number of Subnets, where n is the number of subnet
bits.
Step 3: Now, subtract the number of subnet bits from the default 24 bits to find the remaining
bits for host addresses: 24 - 2 = 22 bits for host addresses.
Step 4: Calculate the subnet mask for the subnets: It will be the default subnet mask (24 bits)
with the additional subnet bits (2 bits) set to 1. This gives us a subnet mask of
"255.255.255.192."
By subnetting, we've efficiently divided the original network into smaller segments, meeting the
requirement for 4 subnets, each with 30 hosts. This allows for better address management and
traffic control within the network.
To subnet the given IP address "192.168.32.8" with a subnet mask of "255.255.255.0" into 4 and 7 subnets,
we need to determine the subnet mask for each case and calculate the subnet ranges.
1. For 4 Subnets:
Step 1: Calculate the number of bits needed to represent 4 subnets: 2^2 = 4, so we need 2 bits for
subnetting.
Step 2: Subtract the subnet bits from the total bits in the default subnet mask (24 bits) to get the host bits: 24
- 2 = 22 bits for hosts.
2. For 7 Subnets:
Step 1: Calculate the number of bits needed to represent 7 subnets: The nearest power of 2 that is equal to
or greater than 7 is 8, which requires 3 bits for subnetting.
Step 2: Subtract the subnet bits from the total bits in the default subnet mask (24 bits) to get the host bits: 24
- 3 = 21 bits for hosts.
Step 3: Calculate the new subnet mask:
These calculations result in the subnet ranges for both 4 and 7 subnets based on the given IP address and
subnet mask.
Network Address Translation (NAT) is a technique used in networking to allow multiple devices
within a local network to share a single public IP address. NAT helps manage the limited
availability of IPv4 addresses and provides security by hiding internal network details from the
external world. Let's understand NAT with an example:
Imagine you have a home network with multiple devices (computers, smartphones, smart
devices) all connected to a router. Your ISP provides you with a single public IP address, but you
have several devices that need to access the internet simultaneously.
Without NAT:
• All devices in your home network would need unique public IP addresses.
• This would quickly exhaust the limited pool of available IPv4 addresses.
With NAT:
• Your router acts as a NAT device. It assigns private IP addresses to the devices within
your home network.
• Private IP addresses are used within your local network and are not routable on the
internet.
Example:
Benefits of NAT:
• IP Conservation: NAT helps reduce the need for multiple public IP addresses, as several
devices share a single public IP.
• Security: NAT acts as a barrier between the public internet and private devices. External
entities don't directly interact with your devices, enhancing security.
• Simplified Configuration: Devices in the private network don't require unique public IP
addresses, simplifying network management.
In summary, Network Address Translation (NAT) is a technique that enables multiple devices
with private IP addresses to share a single public IP address for accessing the internet. NAT
enhances security and conserves public IP addresses while allowing internal devices to
communicate with the external network.
FIREWALL
Example 1: Basic Firewall Rule Let's say you want to allow only incoming SSH (Secure
Shell) connections to your Linux server:
1. You set up a firewall rule that allows incoming traffic on port 22 (SSH port).
2. Any external device trying to establish an SSH connection to your server will
be allowed, while other incoming traffic is blocked.
Example 2: Web Server and HTTP Traffic Imagine you're running a web server and
want to permit only HTTP (port 80) and HTTPS (port 443) traffic while blocking other
types:
1. You configure your firewall to allow incoming traffic on ports 80 and 443.
2. This allows users to access your website over HTTP and HTTPS, while other
ports remain closed for security.
Example 3: Outgoing Traffic Control You might want to restrict outgoing traffic from
your network:
1. You set up a firewall rule to block all outgoing traffic on port 25 (SMTP) except
from your mail server.
2. This prevents unauthorized devices on your network from sending emails
directly, reducing the risk of spam.
Example 4: Stateful Inspection Firewalls can also perform stateful inspection, which
tracks the state of active connections:
1. When you initiate an outbound request (e.g., visiting a website), the firewall
dynamically opens a port for the response traffic.
2. Once the communication is complete, the firewall automatically closes that
port.
Example 5: Application Filtering Modern firewalls offer application filtering, allowing
or blocking specific applications:
1. You can configure the firewall to allow certain applications (e.g., web
browsers) to access the internet while blocking others (e.g., peer-to-peer file
sharing).
Example 6: Logging and Reporting Firewalls can log traffic and events for analysis
and troubleshooting:
In Linux, the built-in firewall management tool is often "iptables" or its successor
"nftables," while distributions like Ubuntu might use "ufw" (Uncomplicated Firewall)
for simplified management. More advanced firewall solutions like "firewalld" provide
dynamic configuration and user-friendly interfaces.
Firewalls are crucial for network security, helping to prevent unauthorized access,
data breaches, and cyberattacks. By defining rules and policies, you control the flow
of traffic in and out of your system, safeguarding your network and resources.
PORTS
• Port 80: HTTP - Web servers use this port to serve websites.
• Port 443: HTTPS - Secure version of HTTP used for encrypted web
communication.
• Port 22: SSH - Secure Shell for remote access and secure file transfers.
• Port 25: SMTP - Simple Mail Transfer Protocol for sending emails.
• Port 53: DNS - Domain Name System for translating domain names to IP
addresses.
• Port 3306: MySQL - Database system port for MySQL database connections.
• Port 8080: Alternative HTTP port often used for web proxies or non-standard
setups.
• Well-known Ports (0-1023): Reserved for standard services like HTTP, FTP,
SMTP.
• Registered Ports (1024-49151): Used for various applications and services.
• Dynamic/Private Ports (49152-65535): Typically used for temporary
connections.
3. Checking Open Ports: In Linux, you can use tools like "netstat" or "ss" to check
open ports and established connections:
# Using netstat
netstat -tuln
ss -tuln
4. Firewall Rules and Ports: Linux firewalls (like iptables, nftables, or firewalld) allow
you to define rules to control which ports are open or closed:
5. Network Services and Ports: Different services use specific ports to function. For
example, a web server uses port 80 for unencrypted HTTP traffic and port 443 for
encrypted HTTPS traffic.
6. Binding to Ports: When you run a server application, it binds to a specific port
number. For instance, a web server binds to port 80 or 443 to listen for incoming
web requests.
DNS
DNS (Domain Name System) in Linux, as well as in general networking, is a crucial service that
translates human-readable domain names (like www.example.com) into IP addresses (like
192.168.1.1). It acts like a phonebook for the internet, making it easier for us to access websites
and services. Here's an explanation with examples:
1. How DNS Works: When you type a website URL into your browser, your computer needs to
find the IP address associated with that domain name to connect to the web server. The DNS
system handles this translation process.
2. DNS Components:
• DNS Client: Your computer acts as a DNS client. When you enter a domain name in your
browser, the DNS client queries DNS servers to resolve the IP address.
• DNS Server: These servers store information about domain names and their
corresponding IP addresses. They provide answers to DNS queries.
1. Your computer sends a DNS query to a DNS resolver. This could be a local DNS server
provided by your ISP or a public DNS server like Google's (8.8.8.8).
2. The resolver checks its cache. If it already knows the IP address for
"www.example.com," it returns the result.
3. If not cached, the resolver contacts a root DNS server to find out which DNS server is
authoritative for the ".com" top-level domain.
4. The root DNS server directs the resolver to the ".com" DNS server.
5. The ".com" DNS server guides the resolver to the DNS server responsible for
"example.com."
6. The "example.com" DNS server finally provides the IP address for "www.example.com"
to the resolver.
7. The resolver sends the IP address to your computer, and your browser can now connect
to the web server.
5. DNS Configuration in Linux: In Linux, DNS configuration involves editing the /etc/resolv.conf
file. This file specifies the DNS servers your system should use for name resolution.
nameserver 8.8.8.8
nameserver 8.8.4.4
• nslookup: Used to query DNS servers for information about domain names and IP
addresses.
• dig (Domain Information Groper): A powerful tool for querying DNS servers.
• nslookup example.com
dig www.example.com
• DNS is an essential part of the internet, enabling seamless browsing by converting
human-friendly domain names into computer-readable IP addresses. It plays a vital role
in connecting users to online resources and services.
Here's a list of 50 essential Linux networking commands along
with examples:
1. ifconfig
2. ip
3. ping
4. traceroute
5. netstat
6. ss
Example: ss -tuln
7. route
Example: route -n
8. dig
9. nslookup
10. hostname
11. iwconfig
12. iw
14. iftop
Example: iftop -n 10
15. tcpdump
16. nmap
17. ssh
18. scp
19. wget
20. curl
21. nc (netcat)
22. telnet
23. arp
Example: arp -a
24. ethtool
25. mtr
26. route
Example: route -n
27. iptables
Example: iptables -L
28. iperf
29. dig
30. ntpdate
31. netcat
32. ifstat
33. ss
Example: ss -tuln
34. host
35. dhclient
36. hostnamectl
37. nmcli
38. smbclient
39. ipcalc
40. route
41. ssh-keygen
43. iptraf
Example: iptraf
44. tcpdump
45. arp-scan
46. hostname
Example: hostname
47. ss
Example: ss -tuln
48. dig
49. iperf3
50. nc (netcat)