Linux Services and Networking, Systemd vs Cron.pdf
cowepep906
11 views
39 slides
Jul 10, 2024
Slide 1 of 39
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
About This Presentation
Linux services and networking
Size: 797.08 KB
Language: en
Added: Jul 10, 2024
Slides: 39 pages
Slide Content
Linux Services and
Networking
1
Service Management in Linux
●Linux provides robust tools for managing system services
●Key tools: Cron and Systemd
●Ensures services run smoothly and efficiently
●Essential for system administrators and DevOps
professionals
2
Overview of Cron
Cron: a time-based job scheduler in Unix-like systems
Used for scheduling repetitive tasks
Cron jobs defined in crontab files
Commonly used for:
●Automated backups
●System maintenance
●Scheduled scripts
3
Crontab Syntax
Crontab file format:
●* * * * * command_to_execute
●Fields: minute, hour, day of month, month, day of week
Examples:
●0 0 * * * /path/to/script.sh (runs daily at midnight)
●0 5 * * 1 /path/to/script.sh (runs every Monday at 5 AM)
4
Managing Cron Jobs
View crontab: crontab -l
Edit crontab: crontab -e
Remove crontab: crontab -r
Use proper permissions and paths
Monitor cron logs for troubleshooting
5
Overview of Systemd
Systemd: a system and service manager for Linux
Provides parallelization capabilities
Uses units to manage services, mounts, and devices
Key commands: systemctl, journalctl
6
Systemd Unit Files
●Unit files: configuration files that define services
●Located in /etc/systemd/system/ and /usr/lib/systemd/system/
●Common unit file sections:
○[Unit]: metadata and dependencies
○[Service]: service-specific settings
○[Install]: installation settings
7
Managing Services with Systemd
Start a service: systemctl start service_name
Stop a service: systemctl stop service_name
Enable a service: systemctl enable service_name
Disable a service: systemctl disable service_name
Check service status: systemctl status service_name
View logs: journalctl -u service_name
8
Key Differences Between Cron and Systemd
●Cron:
○Time-based scheduling
○Simpler, lightweight
○Ideal for repetitive tasks
●Systemd:
○More comprehensive service management
○Handles dependencies and parallelization
○Suitable for complex service orchestration
Introduction to Logging
●Importance of logging in system administration and DevOps
●Types of logs: application logs, system logs
●Overview of common logging tools and their benefits
11
Types of Logs and Locations
●Application logs:
○Located in application-specific directories (e.g., /var/log/nginx/)
○Example tools: tail, grep for real-time monitoring
●System logs:
○Managed by the operating system (e.g., /var/log/syslog,
/var/log/messages)
○Example tools: journalctl for systemd logs on Linux
12
Useful Command-Line Tools
tail command:
●Used for viewing the last few lines of a log file
●Example: tail -n 100 /var/log/syslog (displays last 100 lines of syslog)
grep command:
●Filters log entries based on a specified pattern
●Example: grep "ERROR" /var/log/nginx/error.log (finds ERROR entries in
nginx error log)
13
Log Rotation
●Importance of log rotation for managing log file size and maintenance
●Example tools: logrotate for automated log rotation configuration
Slide 5: Monitoring and Analysis
●Monitoring logs:
○Use watch command to monitor log files in real-time
○Example: watch -n 10 tail /var/log/syslog (updates syslog every 10
seconds)
●Log analysis:
○Use awk or sed for simple log parsing and analysis tasks
○Example: awk '{print $4, $5, $6}' /var/log/apache2/access.log
(extracts specific fields from Apache access log)
14
Introduction to File Sharing and Tools
File sharing facilitates collaboration by enabling seamless access to files across networks.
Key file sharing tools include:
●SCP (Secure Copy): Securely transfers files between systems using SSH.
●Rsync (Remote Sync): Efficiently synchronizes files and directories locally or across
networks.
●Samba: Provides file and print services for seamless integration between Linux and
Windows environments.
15
Usage and Examples
SCP (Secure Copy):
●Used for one-time secure file transfers.
●Example: scp local_file.txt remote_user@remote_host:/remote/path/
Rsync (Remote Sync):
●Ideal for synchronizing large directories or backups.
●Example: rsync -avz /local/directory/
remote_user@remote_host:/remote/directory/
Samba:
●Enables seamless file and printer sharing across heterogeneous networks.
●Example: Setting up a shared folder accessible from Windows and Linux.
16
Key Differences
SCP (Secure Copy):
●Focuses on secure file transfer over SSH.
●Example: scp file.txt user@remote_host:/path/to/destination
Rsync (Remote Sync):
●Efficiently synchronizes files and directories, minimizing data transfer.
●Example: rsync -avz /local/dir/ user@remote_host:/remote/dir/
Samba:
●Provides file and print services for Windows clients in a Linux environment.
●Example: Setting up a shared folder accessible from Windows and Linux.
17
Network Overview
●Network Components
○Nodes: Devices connected to the network (e.g., computers, servers, routers).
○Networks: Interconnected nodes facilitating communication.
○Protocols: Rules governing communication (e.g., TCP/IP, HTTP).
●Types of Networks
○LAN (Local Area Network): Limited geographical area (e.g., office building).
○WAN (Wide Area Network): Spans large geographical areas (e.g., across cities or countries).
○VPN (Virtual Private Network): Securely extends a private network across a public network (e.g.,
internet).
●Network Devices
○Router: Directs data between networks.
○Switch: Connects devices within a LAN.
○Firewall: Controls incoming and outgoing network traffic based on security rules.
18
TCP/IP Model
Importance of network architecture understanding.
Overview of TCP/IP model layers:
●Application Layer
●Transport Layer
●Internet Layer
●Link Layer
Application Layer: Interacts directly with applications (e.g., HTTP, FTP).
Transport Layer: Manages data delivery (e.g., TCP, UDP).
Internet Layer: Handles addressing and routing (e.g., IP).
Link Layer: Manages physical connection (e.g., Ethernet).
19
Network Security
Encryption: Secures data in transit (e.g., SSL/TLS).
Access Control: Restricts network access based on user roles.
Intrusion Detection/Prevention Systems (IDS/IPS): Monitor and
respond to network threats.
20
IP Addressing and Subnetting
IPv4 vs. IPv6: Differences and benefits of IPv6.
Subnetting: Divides networks into smaller segments.
DHCP (Dynamic Host Configuration Protocol): Automates IP address assignment.
21
Introduction to Routing
●Routing: The process of directing network traffic from its source to its destination
across multiple networks.
●Importance: Efficient routing ensures timely and reliable delivery of data.
Concept of Routing
●Routing Logic: Determines the best path for data packets based on routing metrics
such as shortest path, lowest latency, or least cost.
●Router Role: Devices that forward data packets between networks based on routing
decisions.
22
Routing Table
Routing Table: A database stored in routers that contains information about known network paths.
Components:
●Destination Network: The IP address or network address of the destination.
●Next Hop: The IP address of the next router or gateway along the path to reach the destination.
●Interface: The network interface through which the router can reach the destination.
Routing Table Example
●Example Entry:
○Destination Network: 192.168.1.0/24
○Next Hop: 10.0.0.1
○Interface: eth0
●Purpose: Helps routers make forwarding decisions based on the destination IP address of incoming packets.
23
Introduction to Network Configuration Tools
Network Configuration Tools: Essential utilities for managing network interfaces in Linux
systems.
Importance: Efficient management of network settings enhances connectivity and
troubleshooting.
ifconfig: Configures and displays network interface parameters.
ip link show: Lists network interfaces and their state.
ip addr show: Displays IP addresses assigned to network interfaces.
ip route: Manages IP routing tables for network communication.
route: Manages IP routing tables for network communication.
ifup / ifdown: Scripts to bring up or down network interfaces.
24
ifconfig, ifup, ifdown
ifconfig: Displays and configures network interface parameters.
Usage:
●View interface details: ifconfig
●Configure interface: sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0
●Enable interface: sudo ifconfig eth0 up
●Disable interface: sudo ifconfig eth0 down
ifup and ifdown: Scripts to bring up or down network interfaces.
Usage:
●Enable interface: sudo ifup eth0
●Disable interface: sudo ifdown eth0
25
route
route: Displays and manipulates IP routing tables.
Usage:
●Show routing table: route -n
●Add a route: sudo route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1
●Delete a route: sudo route del -net 192.168.2.0 netmask 255.255.255.0
26
IP
●ip link show: Lists network interfaces and their state.
●Usage:
○Display all interfaces: ip link show
○Show specific interface: ip link show eth0
●ip addr show: Displays IP addresses assigned to network interfaces.
●Usage:
○Show IP addresses: ip addr show
○Show addresses for specific interface: ip addr show eth0
●ip route: Displays and manipulates IP routing tables.
●Usage:
○Show routing table: ip route show
○Add a route: sudo ip route add 192.168.2.0/24 via 192.168.1.1 dev eth0
○Delete a route: sudo ip route del 192.168.2.0/24
27
Introduction to Network Troubleshooting
Tools
Network Troubleshooting Tools: Essential utilities for diagnosing and resolving network
issues in Linux systems.
Summary:
●Ping: Tests connectivity to remote hosts using ICMP echo requests.
●Traceroute: Traces the path packets take from source to destination.
●/etc/services: Lists network services and associated port numbers.
●Netstat: Displays network connections, routing tables, and interface statistics.
28
Ping
Ping: Verifies connectivity to a remote host by sending ICMP echo requests.
Usage:
●Test connectivity: ping google.com
●Specify number of packets: ping -c 5 google.com
●Continuous ping: ping -i 2 google.com
29
Traceroute
Traceroute: Traces the route packets take from source to destination.
Usage:
●Trace route to destination: traceroute google.com
●Specify maximum hops: traceroute -m 30 google.com
●Use ICMP instead of UDP: traceroute -I google.com
30
/etc/services
●/etc/services: Lists network services and associated port numbers.
●Usage:
○View services and ports: cat /etc/services
○Lookup specific service: grep ssh /etc/services
31
Netstat
Netstat: Displays network connections, routing tables, interface statistics, and more.
Example: netstat -at
The netstat -a command shows the listening and non-listening sockets for network
connections, the -t flag shows only tcp connections.
32
Introduction to DNS (Domain Name System)
DNS (Domain Name System): Vital system that translates domain names (e.g.,
google.com) into IP addresses (e.g., 192.168.1.1).
Importance:
●Internet Navigation: Enables users to access websites and services using
human-readable domain names.
●Network Communication: Essential for devices to locate and communicate with each
other across networks.
●Service Availability: Ensures reliable and efficient internet services by resolving
domain names to IP addresses accurately.
33
Components of DNS
DNS Components:
●DNS Resolver: Client software that initiates DNS queries.
●DNS Server: Stores DNS records and responds to queries from resolvers.
●DNS Zones: Administrative domains managed by DNS servers.
●DNS Records: Information stored in DNS databases (e.g., A, AAAA, CNAME, MX records).
34
Handling DNS Requests
●DNS Request Process:
○Step 1: Resolver sends a query to the local DNS server.
○Step 2: Local DNS server checks its cache; if not found, it queries authoritative
DNS servers.
○Step 3: Authoritative DNS server responds with the requested DNS record.
○Step 4: Response is returned to the resolver, which then resolves the domain
name.
35
/etc/hosts File
/etc/hosts File: Local text file mapping IP addresses to hostnames on a system.
Purpose:
●Provides local hostname resolution without querying DNS servers.
Practical Use Cases:
●Local Hostname Resolution:
○127.0.0.1 localhost
○192.168.1.10 myserver.example.com
●Override DNS Resolution:
○192.168.1.100 internal.example.com
Benefits:
●Speeds up access to local resources.
●Facilitates testing and development environments.
36
DNS Tools: nslookup
nslookup: Command-line tool to query DNS servers and resolve hostnames.
Usage:
●Query DNS server: nslookup google.com
●Reverse lookup: nslookup 8.8.8.8
37
DNS Tools: dig
dig (Domain Information Groper): Advanced DNS querying tool for DNS troubleshooting.
Usage:
●Query DNS records: dig google.com
●Specify DNS server: dig @8.8.8.8 google.com
●Query specific record types: dig MX google.com
38
Assignment: Network Configuration and Troubleshooting
Objective: Configure network settings, troubleshoot DNS resolution, and utilize network troubleshooting tools on a local Linux machine.
Part 1: Network Configuration
1.Set Up Network Interface:
○Configure your primary network interface (eth0 or enp0s3) with a static IP address 192.168.1.100 and netmask
255.255.255.0 using the appropriate command (ifconfig or ip).
2.Verify Network Configuration:
○Use ip addr show or ifconfig to confirm the interface settings and ensure connectivity to your local network.
Part 2: DNS Configuration and Troubleshooting
3.Edit /etc/hosts File:
Edit the /etc/hosts file to include the following entries:
127.0.0.1 localhost
192.168.1.100 myserver.example.com
○
4.Test DNS Resolution:
○Verify DNS resolution for localhost and myserver.example.com using ping and nslookup.
39
You have to submit a pdf containing screenshots of
running the commands and their outputs here