Do Virtual Machine Require Network Security?

Do Virtual Machine Require Network Security?


1. Enable Firewall Protection

Use UFW (Ubuntu) or Firewalld (CentOS/AlmaLinux) to control access.

Example Login server (Ubuntu)

Sudo ufw status

sudo ufw enable

sudo ufw allow 22/tcp                  # Allow SSH

sudo ufw allow 80/tcp                 # Allow HTTP

 sudo ufw deny 3306              # Block MySQL from public access

sudo ufw reload

sudo ufw status

Example (CentOS/AlmaLinux):

sudo systemctl start firewalld

sudo firewall-cmd –permanent –add-service=ssh

sudo firewall-cmd –permanent –add-port=8080/tcp       # Allow  HTTPS

sudo firewall-cmd –reload

2. Use Private Networking (Avoid Public Exposure)

If VMs do not need internet access, use private/internal networks in VirtualBox, VMware, or Proxmox.

Example:

1 . In VirtualBox, set the network to “Internal Network” instead of “Bridged Adapter”.

2 . In AWS/Azure/GCP, assign private IPs and avoid direct internet exposure.

3. Secure SSH Access

   Disable root login

       sudo nano /etc/ssh/sshd_config

       Set :     PermitRootLogin no

      Restart SSH:    sudo systemctl restart ssh

Use SSH keys instead of passwords:

     ssh-keygen -t rsa -b 4096

     ssh-copy-id user@your-vm-ip     

        How ssh-copy-id Works

  1. It copies your SSH public key (~/.ssh/id_rsa.pub) to the remote server.
  2. It adds the key to the remote server’s ~/.ssh/authorized_keys file.
  3. Once set up, you can SSH into the remote server without entering a password.
4. Use Intrusion Detection System (IDS)

    Install Fail2Ban to block repeated unauthorized login attempts

         sudo apt install fail2ban -y # Ubuntu

         sudo yum install fail2ban -y # CentOS/AlmaLinux

         sudo systemctl enable fail2ban –now

5. Restrict Network Access with iptables

      Allow only specific IPs to access SSH:

             sudo iptables -A INPUT -p tcp –dport 22 -s YOUR_IP -j ACCEPT   

             sudo iptables -A INPUT -p tcp –dport 22 -j DROP

6. Keep Software and OS Updated

    Regularly update your system to fix vulnerabilities:

    sudo apt update && sudo apt upgrade -y             # Ubuntu

    sudo yum update -y                                                   # CentOS/AlmaLinux

7. Enable Logging and Monitoring

   Check logs for suspicious activity:

       sudo cat /var/log/auth.log # Ubuntu

       sudo cat /var/log/secure # CentOS

How do I connect to my Linux VPS using SSH? A detailed guide: Do Virtual Machine Require Network Security?



Source link