Tuesday, December 31, 2024

Linux 101: Part 5 - Networking and Security Basics in Linux



In this fifth part of our Linux 101 series, we will explore essential networking concepts and security basics in Linux. Understanding these topics is crucial for managing servers, troubleshooting network issues, and securing a Linux environment.

Understanding Linux Networking

Linux provides various tools and commands to manage and troubleshoot network connections. Below are some fundamental networking concepts:

  • IP Address: A unique identifier for a device on a network.
  • Subnet Mask: Defines the network and host portion of an IP address.
  • Gateway: The router that connects a local network to other networks.
  • DNS (Domain Name System): Resolves domain names into IP addresses.
  • MAC Address: The hardware address of a network interface.

Checking Network Configuration

Use the following commands to view network details:

  • Check IP Address:

    ip a
    

    or

    ifconfig
    
  • Check Network Routes:

    ip route show
    

    or

    route -n
    
  • Check DNS Configuration:

    cat /etc/resolv.conf
    

Testing Network Connectivity

  • Ping a Host (Check if a server is reachable):
    ping -c 4 google.com
    
  • Check Open Ports on a System:
    netstat -tulnp
    
    or
    ss -tulnp
    
  • Traceroute (Check network path to a destination):
    traceroute google.com
    
  • DNS Lookup:
    nslookup google.com
    
    or
    dig google.com
    

Network Configuration and Management

Assigning an IP Address

Manually set an IP address using:

sudo ip addr add 192.168.1.100/24 dev eth0

Bringing Network Interfaces Up/Down

  • Disable a network interface:
    sudo ip link set eth0 down
    
  • Enable a network interface:
    sudo ip link set eth0 up
    

Security Basics in Linux

Security is a critical aspect of managing a Linux system. Below are some fundamental security practices:

Managing User Access

  • Locking a User Account:
    sudo passwd -l username
    
  • Unlocking a User Account:
    sudo passwd -u username
    
  • Checking Last Login of a User:
    last username
    

Managing Firewalls

Linux includes built-in firewall tools such as iptables and ufw (Uncomplicated Firewall).

  • Enable UFW:
    sudo ufw enable
    
  • Allow SSH Connections:
    sudo ufw allow ssh
    
  • Block a Specific IP Address:
    sudo ufw deny from 192.168.1.10
    
  • Check Firewall Rules:
    sudo ufw status
    

Checking System Logs

Log files store critical system activity and security events.

  • View Authentication Logs:
    cat /var/log/auth.log
    
  • View System Logs:
    journalctl -xe
    
  • View Failed Login Attempts:
    sudo faillog -a
    

Securing SSH

  • Disable Root Login via SSH: Edit the SSH configuration file:
    sudo nano /etc/ssh/sshd_config
    
    Set:
    PermitRootLogin no
    
    Restart SSH service:
    sudo systemctl restart sshd
    

Keeping Your System Updated

Regularly update your Linux system to patch security vulnerabilities:

  • For Debian/Ubuntu:
    sudo apt update && sudo apt upgrade -y
    
  • For Fedora/RHEL:
    sudo dnf update -y
    
  • For Arch Linux:
    sudo pacman -Syu
    

Conclusion

This article introduced fundamental Linux networking and security concepts. In the next part, we will cover Linux Process and Job Management to help you manage running applications and system performance.

Stay tuned for Linux 101: Part 6 – Process and Job Management in Linux!