Sitemap
Onyedikachi Obioma Ofooha

Onyedikachi Obioma Ofooha

Tech Enthusiast

Press enter or click to view image in full size

Advanced Networking on Linux

17 min readJan 3, 2025

--

The objective of this write up is to teach readers advanced networking concepts, protocols, configuration techniques, and troubleshooting on Linux systems. Readers will gain hands-on experience in network management, configuration, security, and optimization through a series of exercises that simulate real-world network environments.

Exercise 1: Basic Linux Network Configuration(Set Up Static IP Addresses)

Objective: Understand and configure basic network settings on a Linux system.

  • Set Up Static IP Addresses: Configure static IP addresses for all VMs to ensure they have fixed addresses.

1.1 Determine Network Interface

  1. Open a terminal on your Linux VM.
  2. Run the following command to identify the active network interface(s):
ip link show
  1. Look for interfaces like eth0, ens33, or similar.

1.2 Assign Static IP

  • Edit the network configuration file:
sudo nano /etc/sysconfig/network-scripts/ifcfg-<interface_name>
  • Add or modify the following lines:
TYPE=Ethernet BOOTPROTO=none IPADDR=<Static_IP> NETMASK=<Subnet_Mask> GATEWAY=<Default_Gateway> ONBOOT=yes
  • Example:
TYPE=Ethernet BOOTPROTO=none IPADDR=192.168.1.10 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 ONBOOT=yes

1.3 Restart Network Service

sudo systemctl restart network

Step 2: Configure DNS and Default Gateway Settings

Ensure that DNS servers and the default gateway are configured in the network configuration file, as shown in Step 1.

Step 3: Verify Network Configuration

Verify Using ifconfig:

ifconfig enp0s3

Check the output for the correct IP address, netmask, and gateway.

Verify Using ip:

ip addr show enp0s3

Ensure the IP address and netmask are correct.

Step 4: Test Connectivity Between All VMs

Use ping to Test Connectivity:

ping 10.0.2.15
ping 10.0.2.2

Confirm that the VMs can communicate with each other and the gateway.

Outcome:

By completing these steps, readers will learn how to configure and troubleshoot basic network settings on Linux systems, ensuring they can set up and verify static IP addresses, DNS, and default gateways.

Exercise 2: DNS and DHCP Configuration

Objective: Configure and troubleshoot DNS and DHCP services on Linux.

DNS Configuration

DNS (Domain Name System) translates human-readable domain names (like www.example.com) into IP addresses that computers use to identify each other on the network.

Key Components:

  • DNS Server: Stores DNS records and resolves domain names to IP addresses.
  • DNS Records: Types include A (Address) records, MX (Mail Exchange) records, and CNAME (Canonical Name) records.

Basic Steps:

  1. Install DNS Server Software: Such as BIND on Linux.
  2. Configure DNS Zone Files: Define domain-to-IP mappings.
  3. Start the DNS Service: Ensure the service is running to handle DNS queries.

DHCP Configuration

DHCP (Dynamic Host Configuration Protocol) automatically assigns IP addresses and other network configurations to devices on the network.

Key Components:

  • DHCP Server: Assigns IP addresses to clients.
  • DHCP Client: Receives an IP address and configuration from the server.

Basic Steps:

  1. Install DHCP Server Software: Such as ISC DHCP on Linux.
  2. Configure DHCP Server: Define IP address ranges, lease times, and other options in the configuration file.
  3. Start the DHCP Service: Ensure the service is running to assign IP addresses to devices.

Together, DNS and DHCP play crucial roles in network management by simplifying IP address management and domain name resolution

Steps: Set Up DNS Server Using BIND

  1. Install BIND (for DNS server)
sudo yum install bind

Edit the Main Configuration File:

  • Open the file to add a zone configuration /etc/named.conf
sudo nano /etc/named.conf

Add the following lines

zone "example.local" {     type master;     file "/etc/named/db.example.local"; };

Create the Zone File: /etc/named/db.example.local

sudo nano /etc/named/db.example.local

Add the following DNS records:

$TTL    604800 @       IN      SOA     ns1.example.local. admin.example.local. (                               2         ; Serial                          604800         ; Refresh                           86400         ; Retry                         2419200         ; Expire                          604800 )       ; Negative Cache TTL ; @       IN      NS      ns1.example.local. ns1     IN      A       10.0.2.15 www     IN      A       10.0.2.16

Set File Permissions:

sudo chown named:named /etc/named/db.example.local sudo chmod 644 /etc/named/db.example.local
  1. Restart BIND Service:
sudo systemctl restart named

Verify DNS Resolution:

dig @10.0.2.15 www.example.local

Step 2: Set Up DHCP Server Using isc-dhcp-server

sudo dnf install dhcp-server

Configure DHCP Server:

  • Edit the main configuration file: /etc/dhcp/dhcpd.conf.
sudo nano /etc/dhcp/dhcpd.conf
  • Add the subnet configuration:
sudo nano /etc/dhcp/dhcpd.conf

Specify Interface for DHCP: /etc/sysconfig/dhcpd

sudo nano /etc/sysconfig/dhcpd
  • Specify the interface (e.g., enp0s3):
INTERFACESv4="enp0s3"

Restart DHCP Service:

sudo systemctl restart dhcpd

Verify DHCP Functionality:

  • On a client machine, use dhclient to request an IP address:
sudo dhclient enp0s3
  • Verify the assigned IP address using ifconfig or ip addr show.

Outcome:

By following these steps, you should be able to configure and troubleshoot DNS and DHCP services on a Linux system

Exercise 3: Network Routing and Subnetting

Objective: Configure network routing and subnetting on Linux systems to understand IP forwarding, static routes, and subnetting principles.

Network Routing

Network routing is the process of selecting the best path for data to travel from one device to another across different networks. Routers are devices that perform this task. They use routing tables and protocols (like OSPF, BGP, and RIP) to determine the most efficient route for data packets, ensuring they reach their destination quickly and reliably.

Subnetting

Subnetting involves dividing a larger network into smaller, more manageable sub-networks (subnets). This helps optimize the use of IP addresses and enhances network security and performance. By assigning smaller groups of IP addresses to different subnets, network traffic can be more efficiently managed, and broadcasts can be limited to specific segments, reducing congestion.

In Summary

  • Routing ensures data finds its way across complex networks using the best path.
  • Subnetting divides networks into smaller parts for better management and efficiency.

These concepts are fundamental to creating efficient and secure network infrastructures. We can achieve both by following the steps below.

Step 1: Enable IP Forwarding

  1. Enable IP Forwarding Temporarily:
sudo sysctl -w net.ipv4.ip_forward=1
  • This command enables IP forwarding immediately but will be reset after a reboot.

Enable IP Forwarding Permanently:

  • To make the change permanent, edit the /etc/sysctl.conf file.
sudo nano /etc/sysctl.conf
  • Add or uncomment the following line:
net.ipv4.ip_forward = 1
  • Apply the changes:
sudo sysctl -p

Step 2: Configure Static Routes

  1. Add a Static Route Temporarily:
  • Use the ip command to add a static route.
sudo ip route add 192.168.2.0/24 via 10.0.2.2 dev enp0s3
  • Explanation:
  • 192.168.2.0/24: Destination network.
  • via 10.0.2.1: Gateway to use for this route.
  • dev enp0s3: Network interface to use.

Add a Static Route Permanently:

  • Edit the network configuration file to add the static route /etc/sysconfig/network-scripts/route-enp0s3
sudo nano /etc/sysconfig/network-scripts/route-enp0s3

Add the following

192.168.2.0/24 via 10.0.2.1 dev enp0s3

Step 3: Verify Routing Configuration

  1. Check Routing Table:
ip route show
  • Verify that the static route has been added.

Test Connectivity: Use ping to test connectivity to the destination network

ping 192.168.2.1

Step 4: Subnetting Practice

  1. Understand Subnetting:
  • Subnetting is the process of dividing a larger network into smaller, more manageable sub-networks (subnets).
  • Example: Dividing the 192.168.1.0/24 network into two subnets with 192.168.1.0/25 and 192.168.1.128/25.

Configure Subnets:

  • Assign IP addresses to interfaces based on the new subnets.
sudo ip addr add 192.168.1.1/25 dev enp0s3 sudo ip addr add 192.168.1.129/25 dev enp0s3
  1. Verify Subnet Configuration:
ip addr show enp0s3
  • Verify that the IP addresses and subnets are correctly configured.

Outcome:

By completing these steps, readers will understand how to enable IP forwarding, configure static routes, and practice subnetting. They will gain hands-on experience with network routing and subnetting on Linux systems.

Exercise 4: Linux Firewall and Security (Advanced)

Objective: Configure and manage Linux firewalls using iptables, firewalld, and nftables, and understand advanced security configurations.

Linux Firewall: A firewall is a system that controls incoming and outgoing network traffic based on security rules. In Linux, tools like iptables, nftables, UFW, and firewalld are used to manage firewall rules. They help protect your system by filtering network packets and blocking unwanted traffic.

Linux Security: Security in Linux involves measures to protect the system from unauthorized access and threats. Key practices include:

  • Regular Updates: Keeping software up-to-date to patch vulnerabilities.
  • User Management: Limiting permissions and using strong passwords.
  • SSH Hardening: Enhancing SSH security by disabling root login and using key-based authentication.
  • Security Tools: Using tools like Fail2Ban to block malicious IPs and SELinux/AppArmor for access control.

These combined efforts ensure a secure and resilient Linux environment.

Using iptables for Firewall Configuration

  1. Install iptables:
sudo yum install iptables-services

Basic iptables Commands:

  • List Rules:
sudo iptables -L -v -n
  • Allow Incoming SSH Connections:
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
  • Block Incoming Traffic from a Specific IP:
sudo iptables -A INPUT -s 192.168.1.100 -j DROP
  • Save iptables Rules:
sudo service iptables save

Advanced iptables Rules:

  • Limit Connection Rate:
sudo iptables -A INPUT -p tcp --dport 80 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT
  • Port Forwarding:
sudo iptables -t nat -A PREROUTING -p tcp --dport 8080 -j DNAT --to-destination 192.168.1.50:80 sudo iptables -t nat -A POSTROUTING -p tcp -d 192.168.1.50 --dport 80 -j MASQUERADE

Step 2: Using firewalld for Dynamic Firewall Management

  1. Install firewalld:
sudo yum install firewalldsh
  1. Start and Enable firewalld:
sudo systemctl start firewalld sudo systemctl enable firewalld

Check firewalld Status:

sudo firewall-cmd --state
  • Allow a Service:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --reload
  • Block a Service:
sudo firewall-cmd --permanent --remove-service=http sudo firewall-cmd --reload

Advanced firewalld Configurations

  • Add a Rich Rule:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.100" reject' sudo firewall-cmd --reload
  • Port Forwarding:
sudo firewall-cmd --permanent --add-forward-port=port=8080:proto=tcp:toport=80:toaddr=192.168.1.50 sudo firewall-cmd --reload

Step 3: Using nftables for Modern Firewall Management

  1. Install nftables:
sudo yum install nftables

Start and Enable nftables:

sudo systemctl start nftables sudo systemctl enable nftables

Basic nftables Commands:

  • List Rules:
sudo nft list ruleset
  • Allow Incoming SSH Connections:
sudo nft add rule inet filter input tcp dport 22 accept
  • Block Incoming Traffic from a Specific IP:
sudo nft add rule inet filter input ip saddr 192.168.1.100 drop

Advanced nftables Configurations:

  • Limit Connection Rate:
sudo nft add rule inet filter input tcp dport 80 limit rate 25/minute burst 100 packets accept
  • Port Forwarding:
sudo nft add rule ip nat prerouting tcp dport 8080 dnat to 192.168.1.50:80 sudo nft add rule ip nat postrouting ip daddr 192.168.1.50 tcp dport 80 masquerade

Outcome:

By completing these steps, readers will understand how to configure and manage firewalls using iptables, firewalld, and nftables. They will gain hands-on experience with firewall rules, port forwarding, and advanced security configurations.

Exercise 5: VPN Setup (OpenVPN or WireGuard)

A VPN (Virtual Private Network) creates a secure and encrypted connection over a less secure network, such as the internet. It ensures that data transmitted between your device and the internet remains private and protected from unauthorized access. Here’s a brief overview:

Key Features:

  1. Encryption: VPNs encrypt data to protect it from being intercepted by hackers or unauthorized entities.
  2. Privacy: They mask your IP address, making your online activities harder to trace back to you.
  3. Security: VPNs provide a secure connection, even when using public Wi-Fi networks.

Common Uses:

  • Secure Remote Access: Allows employees to securely access company resources from remote locations.
  • Privacy Protection: Protects personal information when browsing the internet.
  • Bypassing Geo-Restrictions: Enables access to content restricted to specific geographical locations.

Types of VPNs:

  1. Remote Access VPN: Connects individual users to a private network, commonly used by remote workers.
  2. Site-to-Site VPN: Connects entire networks to each other, often used to link different office locations of an organization.

Popular VPN Protocols:

  • OpenVPN: Open-source and highly secure.
  • WireGuard: Modern, fast, and lightweight.
  • IPsec: Widely used for secure network connections.

In summary, a VPN provides a secure and private way to connect to the internet, protecting your data and enhancing your online privacy.

Installing and configuring OpenVPN involves a few key steps to set up a secure Virtual Private Network (VPN) connection.

Step 1: Install OpenVPN

sudo yum install epel-release sudo yum install openvpn

Step 2: Generate Server and Client Certificates

Set Up the Easy-RSA Package:

Easy-RSA is a toolkit for managing certificates. Install it with:

sudo yum install easy-rsa

Initialize the PKI and Generate CA Certificate:

make-cadir ~/openvpn-ca cd ~/openvpn-ca source ./vars ./clean-all ./build-ca
  1. Generate Server Certificate and Key:
./build-key-server server

Generate Client Certificate and Key

./build-key client1

Generate Diffie-Hellman Parameters:

./build-dh

Step 3: Configure the OpenVPN Server

Copy the Sample Configuration File:

sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/ sudo gzip -d /etc/openvpn/server.conf.gz

Edit the Server Configuration File:

  • Open the configuration file and set the necessary parameters, such as the paths to the server’s certificate and key, and the Diffie-Hellman parameters.
sudo nano /etc/openvpn/server.conf

Enable IP Forwarding:

  • Edit the /etc/sysctl.conf file to enable IP forwarding.
sudo nano /etc/sysctl.conf
  • Add or uncomment the following line:
net.ipv4.ip_forward = 1
  • Apply the changes:
sudo sysctl -p

Start and Enable OpenVPN Service:

sudo systemctl start openvpn@server sudo systemctl enable openvpn@server

Step 4: Configure the OpenVPN Client

  1. Copy the Sample Client Configuration File:
sudo cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf ~/client1.ovpn

Edit the Client Configuration File:

  • Open the client configuration file and set the server’s IP address or domain name, and the paths to the client’s certificate and key.
nano ~/client1.ovpn

Transfer the Client Configuration File and Certificates:

  • Transfer the client1.ovpn file and the client certificate and key to the client machine.

Start the OpenVPN Client:

  • On the client machine, start the OpenVPN client using the configuration file:
sudo openvpn --config client1.ovpn

By following these steps, you can establish a secure VPN connection using OpenVPN.

Setting Up WireGuard

Step 1: Install WireGuard

Update Package List and Install WireGuard:

sudo yum install epel-release sudo yum install wireguard-tools

Step 2: Generate Keys

Generate Private and Public Keys:

umask 077 wg genkey | tee privatekey | wg pubkey > publickey

Step 3: Configure the WireGuard Server

Create a Configuration File:

sudo nano /etc/wireguard/wg0.conf
  • Example configuration:
[Interface] PrivateKey = <server_private_key> Address = 10.0.0.1/24 ListenPort = 51820  [Peer] PublicKey = <client_public_key> AllowedIPs = 10.0.0.2/32

Enable IP Forwarding:

sudo nano /etc/sysctl.conf
  • Add or uncomment:
net.ipv4.ip_forward = 1

Apply changes:

sudo sysctl -p

Start and Enable WireGuard:

sudo wg-quick up wg0 sudo systemctl enable wg-quick@wg0

Step 4: Configure the WireGuard Client

Get Onyedikachi Obioma Ofooha’s stories in your inbox

Join Medium for free to get updates from this writer.

Generate Client Keys:

umask 077 wg genkey | tee client_privatekey | wg pubkey > client_publickey

Create a Client Configuration File:

nano ~/client-wg0.conf
  • Example configuration:
[Interface] PrivateKey = <client_private_key> Address = 10.0.0.2/24  [Peer] PublicKey = <server_public_key> Endpoint = <server_ip>:51820 AllowedIPs = 0.0.0.0/0

Start the WireGuard Client:

sudo wg-quick up client-wg0.conf

Outcome:

By completing these steps, you will have a secure VPN setup using either OpenVPN or WireGuard, providing secure remote access to your network.

Exercise 6: Network Monitoring and Performance Optimization

Objective: Monitor and optimize network performance.

Network Monitoring

  • Purpose: Continuous observation of a network to ensure its performance, availability, and security.
  • Tools: Tools like Netstat, ss, tcpdump, Nagios, Zabbix, PRTG, and SolarWinds help track network activity.

Key Metrics:

  • Bandwidth Usage: Monitoring the amount of data transmitted over the network.
  • Latency: Measuring the time it takes for data to travel from source to destination.
  • Uptime/Downtime: Tracking the availability of network devices and services.
  • Error Rates: Identifying issues like packet loss and transmission errors.
  • Benefits: Detects issues early, helps in troubleshooting, ensures network reliability and security.

Performance Optimization

  • Purpose: Enhancing the efficiency and speed of a network to provide a better user experience.
  • Techniques:
  • Load Balancing: Distributes traffic across multiple servers to avoid overloading any single server.
  • QoS (Quality of Service): Prioritizes critical network traffic to ensure important services get the necessary bandwidth.
  • Caching: Stores frequently accessed data closer to the user to reduce latency.
  • Network Segmentation: Divides the network into smaller segments to reduce congestion and improve performance.
  • Upgrading Hardware: Replacing outdated hardware with more efficient and faster devices.

How They Work Together

  • Proactive Monitoring: Identifying potential performance issues before they affect users.
  • Data-Driven Optimization: Using insights from monitoring to make informed decisions on improving network performance.

By combining network monitoring with performance optimization, organizations can ensure a reliable, fast, and efficient network.

Step 1: Monitor Network Traffic

1.1 Using netstat

Run the following command to view active network connections:

netstat -tuln
  • -t: Shows TCP connections.
  • -u: Shows UDP connections.
  • -l: Lists listening ports.
  • -n: Displays IP addresses and ports numerically.

1.2 Using ss (Socket Statistics)

  1. Use ss to display detailed socket information:
ss -tunap
  • -t: Shows TCP connections.
  • -u: Shows UDP connections.
  • -n: Displays IP numerically.
  • -a: Displays all sockets.
  • -p: Displays the process using the socket.

1.3 Using tcpdump

  1. Capture network packets in real-time:
sudo tcpdump -i <interface> -nn
  1. Replace <interface> with your active network interface (e.g., enp0s3).
  2. To save the output to a file:
sudo tcpdump -i <interface> -w capture.pcap
  • You can open the .pcap file in Wireshark for detailed analysis.

1.4 Using iftop

Install iftop (if not already installed):

sudo yum install iftop

Run iftop to monitor live bandwidth usage:

sudo iftop -i <interface>

1.5 Using Wireshark

  1. Open Wireshark and select the desired network interface.
  2. Start capturing packets to analyze traffic visually.

Step 2: Analyze Network Traffic

Using nmap

  1. Scan open ports on a specific host:
nmap -sT <target_IP>

Perform a network scan to discover devices:

nmap -sn 192.168.1.0/24
  1. Replace 192.168.1.0/24 with your network's IP range.

Step 3: Optimize Network Interfaces

3.1 Adjust MTU (Maximum Transmission Unit)

Check the current MTU:

ip link show <interface>

Set a new MTU value:

sudo ip link set <interface> mtu <value>

Example:

sudo ip link set enp0s3 mtu 1400

3.2 Tune TCP Buffer Sizes

  1. View current TCP buffer sizes:
cat /proc/sys/net/ipv4/tcp_rmem cat /proc/sys/net/ipv4/tcp_wmem
  1. Adjust buffer sizes (temporary change):
sudo sysctl -w net.ipv4.tcp_rmem="4096 87380 6291456" sudo sysctl -w net.ipv4.tcp_wmem="4096 16384 4194304"
  1. For permanent changes, edit /etc/sysctl.conf:
sudo nano /etc/sysctl.conf

Add:

net.ipv4.tcp_rmem = 4096 87380 6291456 net.ipv4.tcp_wmem = 4096 16384 4194304

Step 4: Monitor Bandwidth Usage

Using ntopng

  1. Install ntopng:
sudo yum install ntopng
  1. Start the service:
sudo systemctl start ntopng

Access the web interface:

  • Open your browser and go to http://<server_IP>:3000.
  • Log in with default credentials (admin / admin).

Step 5: Measure Network Throughput

Using iperf3

  1. Install iperf3:
sudo yum install iperf3

On one VM, run iperf3 in server mode:

iperf3 -s
  1. On another VM, run iperf3 in client mode to test throughput:
iperf3 -c <server_IP>

Outcome

By completing these tasks, readers will:

  1. Learn how to monitor network traffic using various tools.
  2. Gain insights into optimizing network parameters for better performance.
  3. Understand how to identify and address network bottlenecks.

Exercise 7: High Availability and Load Balancing

Objective:

To configure high availability and load balancing for a web service using Linux tools.

High Availability (HA)

High Availability is the practice of ensuring that a system or service remains accessible and operational for as long as possible, minimizing downtime. This is achieved through redundancy, failover mechanisms, and efficient resource management. Key components of HA include:

  • Redundancy: Having multiple instances of critical components (e.g., servers, databases) to take over in case of failure.
  • Failover: Automatic switching to a standby system or component when the primary system fails.
  • Clustering: Grouping multiple servers to work together, sharing the load and providing backup in case one server fails.

Load Balancing

Load Balancing is the process of distributing network or application traffic across multiple servers to ensure no single server becomes overwhelmed. This helps in improving performance, reliability, and availability. Key benefits of load balancing include:

  • Scalability: Distributing traffic evenly across servers allows for handling increased loads.
  • Performance: Improves response times and reduces latency by directing traffic to the least busy server.
  • Reliability: If one server fails, the load balancer redirects traffic to other operational servers.

How They Work Together

  • HA with Load Balancing: Load balancers can distribute traffic across multiple redundant servers, ensuring high availability by diverting traffic away from any failed server to those that are still operational. This combination ensures both performance and uptime.

High Availability focuses on minimizing downtime and ensuring continuous operation, while Load Balancing distributes traffic to improve performance and prevent overloads. Together, they form a robust system that enhances both reliability and efficiency.

Step-by-Step Guide to setup

Step 1: Set Up Two Web Servers

Install a Web Server (Apache or Nginx) on both VMs designated as web servers:

sudo yum install httpd
  • Start and enable the web server:
sudo systemctl start apache2 sudo systemctl enable apache2

Create a Test Page on Each Web Server:

  • Edit the default index.html file to identify the server:
echo "Web Server 1" | sudo tee /var/www/html/index.html  # On Server 1 echo "Web Server 2" | sudo tee /var/www/html/index.html  # On Server 2

Step 2: Install and Configure HAProxy for Load Balancing

Install HAProxy:

sudo yum install haproxy

Configure HAProxy:

  • Edit the HAProxy configuration file:
sudo nano /etc/haproxy/haproxy.cfg
  • Add the following configuration:
frontend http_front     bind *:80     default_backend web_servers  backend web_servers     balance roundrobin     server web1 <web1_IP>:80 check     server web2 <web2_IP>:80 check
  • Replace <web1_IP> and <web2_IP> with the IP addresses of the two web servers.

Start HAProxy:

sudo systemctl start haproxy sudo systemctl enable haproxy

Step 3: Set Up High Availability (Optional)

If you want to make the load balancer itself highly available:

Install Keepalived:

sudo yum install keepalived

Configure Keepalived for Virtual IP Address:

  • Edit the Keepalived configuration file:
sudo nano /etc/keepalived/keepalived.conf
  • Add the following:
vrrp_instance VI_1 {     state MASTER     interface <network_interface>     virtual_router_id 51     priority 100     advert_int 1     authentication {         auth_type PASS         auth_pass 12345     }     virtual_ipaddress {         <virtual_IP>     } }
  • Replace <network_interface> with your active interface (e.g., enp0s3) and <virtual_IP> with a free IP address in your network.

Restart Keepalived:

sudo systemctl restart keepalived

Step 4: Test Load Balancing

  1. Open a browser or use curl to access the HAProxy server:
curl http://<haproxy_IP>
  1. Refresh the page multiple times. You should see responses alternating between “Web Server 1” and “Web Server 2” due to round-robin balancing.

Step 5: Simulate a Failover Scenario

Stop one of the web servers:

sudo systemctl stop apache2  # On Server 1 or Server 2

Access the HAProxy server again. It should automatically redirect traffic to the remaining active web server.

Outcome

By completing this exercise, readers will:

  1. Understand the concepts of load balancing and high availability.
  2. Learn to configure HAProxy for load balancing.
  3. Gain experience in failover scenarios and ensuring uptime for web services.

Exercise 8: Network Troubleshooting

Objective:

To diagnose and resolve common networking issues on Linux systems using standard troubleshooting tools and techniques.

Network Troubleshooting is the process of diagnosing and resolving network issues to ensure smooth and efficient operation. Here’s a brief overview:

1. Identify the Problem:

  • Symptoms Check: Determine what the issue is (e.g., slow connection, no internet access, dropped packets).
  • Scope: Identify which devices or areas are affected.

2. Gather Information:

  • Use Network Tools: Tools like ping, traceroute, and nslookup help diagnose connectivity issues.
  • Check Logs: Review logs from network devices and servers for error messages.

3. Common Troubleshooting Steps:

  • Ping Test: Verify connectivity to a specific IP address.
  • Traceroute: Identify the path packets take to reach a destination and locate any bottlenecks.
  • Check IP Configuration: Ensure devices have the correct IP settings.
  • Restart Devices: Sometimes, simply restarting routers, switches, or computers can resolve issues.
  • Check Cables and Connections: Ensure physical connections are secure and cables are not damaged.

4. Isolation and Testing:

  • Segment Isolation: Isolate different network segments to pinpoint the problematic area.
  • Swap Components: Replace suspect cables, ports, or devices to test if the issue persists.

5. Resolution and Documentation:

  • Implement Fixes: Apply the necessary fixes based on the diagnosis.
  • Test: Ensure the issue is resolved and the network is functioning normally.
  • Document: Keep records of the problem, steps taken, and the resolution for future reference.

Effective network troubleshooting involves a systematic approach to identify, isolate, and resolve network issues to maintain optimal performance.

Step-by-Step Guide

Step 1: Simulate Network Issues

Incorrect IP Configuration:

  • Assign an incorrect IP address to a VM:
sudo ip addr add 192.168.100.200/24 dev <interface>
  • Replace <interface> with the active network interface (e.g., enp0s3).
  • Omit the default gateway:
sudo ip route delete default

DNS Resolution Problems:

  • Modify the /etc/resolv.conf file to point to a non-functional DNS server:
sudo nano /etc/resolv.conf
  • Add:
nameserver 8.8.8.9  # Incorrect DNS

Routing Problems:

  • Remove an existing route:
sudo ip route del <destination_network>
  • Example:
sudo ip route del 192.168.1.0/24

Firewall Misconfigurations:

  • Block ICMP (ping) requests:
sudo iptables -A INPUT -p icmp --icmp-type echo-request -j DROP

Step 2: Diagnose Issues

Check IP Address Configuration:

  • Use ip addr to display the IP address:
ip addr show
  • Verify the default gateway:
ip route

Test DNS Resolution:

  • Use ping to check DNS resolution:
ping google.com
  • Use nslookup to query the DNS server:
nslookup google.com
  1. Verify Network Connectivity:
  • Use ping to test connectivity between VMs:
ping <target_IP>
  • Use traceroute to track the route packets take:
traceroute <target_IP>
  • Install traceroute if not already available:
sudo yum install traceroute

Inspect Firewall Rules:

  • Check active iptables rules:
sudo iptables -L -n -v
  • If using firewalld, list active zones and rules:
sudo firewall-cmd --list-all

Capture Traffic for Analysis:

  • Use tcpdump to capture network traffic:
sudo tcpdump -i <interface> -nn
  • Save captured traffic for analysis:
sudo tcpdump -i <interface> -w troubleshooting.pcap

Step 3: Resolve Issues

Fix IP Configuration:

  • Assign the correct IP address and default gateway:
sudo ip addr add 192.168.1.100/24 dev <interface> sudo ip route add default via 192.168.1.1
  1. Restore DNS Settings:
  • Edit /etc/resolv.conf and provide the correct DNS server:
sudo nano /etc/resolv.conf
  • Add:
nameserver 8.8.8.8
  1. Correct Routing Issues:
  • Add missing routes:
sudo ip route add 192.168.1.0/24 via 192.168.1.1

Adjust Firewall Rules:

  • Allow ICMP traffic:
sudo iptables -D INPUT -p icmp --icmp-type echo-request -j DROP
  • Reload firewalld to reset to default:
sudo firewall-cmd --reload

Step 4: Verify Resolutions

Check Connectivity:

  • Test with ping:
ping google.com ping <target_VM_IP>

Verify DNS Resolution:

  • Use dig or nslookup:
nslookup google.com

Confirm Routing Table:

  • Check routes:
ip route

Test Firewall Configurations:

  • Scan open ports using nmap:
nmap -sT <target_VM_IP>

Outcome

By completing this exercise, readers will:

  1. Learn to simulate and diagnose common network issues.
  2. Gain hands-on experience using Linux network troubleshooting tools.
  3. Develop skills to systematically resolve network misconfigurations.

Final Outcome

Through these exercises, readers will develop a comprehensive understanding of Linux networking, covering configuration, security, troubleshooting, and optimization. This prepares them for real-world scenarios and advanced networking roles.

--

--