How to Assign a static IP to a VPS?

Helposoft Staff

Administrator
Staff member
Points
178
To assign a static IP address to a VM in Proxmox VE, you'll need to configure the network settings inside the VM's operating system. Here’s a step-by-step guide on how to do this, assuming you're using AlmaLinux (or a similar Linux distribution):

1. Access the VM Console

  1. Open Proxmox VE Web Interface:
    • Navigate to your Proxmox VE web interface.
  2. Select Your VM:
    • Click on the VM you want to configure.
  3. Open the Console:
    • Go to the "Console" tab to access the VM’s console.

2. Configure Network Settings Inside the VM

You need to configure the network settings inside the VM's operating system to assign the static IP address. Here’s how to do it for AlmaLinux and similar Linux distributions:

For AlmaLinux 8 (or CentOS/RHEL 8)

  1. Log into the VM:
    • Log in using your root or a user with sudo privileges.
  2. Edit the Network Configuration File:
    • The network configuration files are located in /etc/sysconfig/network-scripts/. Find the appropriate file, usually named ifcfg-eth0 or ifcfg-enp0s3 (the name might differ based on your network interface).
Code:
nano /etc/sysconfig/network-scripts/ifcfg-eth0
or
Code:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
  1. Modify the Configuration File:
    • Change the file to configure the static IP. Here’s an example configuration for a static IP:

      Code:
      TYPE=Ethernet
      BOOTPROTO=static
      NAME=eth0
      DEVICE=eth0
      ONBOOT=yes
      IPADDR=31.172.XX.XXX
      NETMASK=255.255.255.0
      GATEWAY=31.172.XX.X
      DNS1=8.8.8.8
      DNS2=8.8.4.4
    • Replace eth0 with your network interface name if it's different, and set the IPADDR, NETMASK, GATEWAY, DNS1, and DNS2 values according to your network configuration.
  2. Restart the Network Service:
    • Apply the changes by restarting the network service:

      Code:
      systemctl restart network
    • Alternatively, you can reboot the VM:

      Code:
      reboot

For AlmaLinux 9 (or CentOS/RHEL 9)

  1. Log into the VM:
    • Log in using your root or a user with sudo privileges.
  2. Use nmcli to Configure Network:
    • For newer systems using NetworkManager, you can configure the static IP using nmcli:

      Code:
      nmcli con show
      Identify the connection name, then set the static IP:

      Code:
      nmcli con mod "YourConnectionName" ipv4.addresses 31.172.XX.XXX/24
      nmcli con mod "YourConnectionName" ipv4.gateway 31.172.XX.X
      nmcli con mod "YourConnectionName" ipv4.dns "8.8.8.8 8.8.4.4"
      nmcli con mod "YourConnectionName" ipv4.method manual
      nmcli con up "YourConnectionName"
    • Replace "YourConnectionName" with the actual name of your network connection.

3. Verify the Static IP Configuration

  1. Check the IP Address:
    • Use the ip command to verify the IP address:

      Code:
      ip a
    • Ensure the interface has the correct static IP assigned.
  2. Test Connectivity:
    • Test network connectivity to ensure the VM can reach external networks:

      Code:
      ping -c 4 google.com
    • Test connectivity to other devices on your network.

4. Proxmox VE Network Configuration (Optional)

If you need to ensure that your VM is properly connected to the Proxmox network bridge:
  1. Check Network Configuration:
    • Verify that the VM's network adapter is connected to the correct bridge (e.g., vmbr0):
      • Go to the "Hardware" tab of your VM in the Proxmox web interface.
      • Ensure the network device is set to the correct bridge.
  2. Apply and Save Changes:
    • Make sure any changes are applied and saved.

Summary

  • Configure the VM's network interface inside the OS to use a static IP address.
  • Restart the network service or reboot the VM to apply the changes.
  • Verify the IP address and network connectivity.
By following these steps, you can assign a static IP address to your VM and ensure that it is properly configured within Proxmox VE. If you encounter issues or need additional assistance, feel free to ask!
 
Top