Configuring a static IP address on a Linux machine involves modifying network configuration files to set a specific IP address, subnet mask, gateway, and DNS servers. The exact steps can vary slightly depending on the Linux distribution you are using, but the general process involves editing relevant configuration files. Here’s a general guide:

Note: You need administrative privileges (such as root or using sudo) to make these changes.

  1. Identify Network Interface:
    Determine the name of the network interface you want to configure. Common interface names include eth0, enp0s3, ens33, etc. You can use the ifconfig or ip addr command to list available interfaces.
  2. Edit Network Configuration File:
    Locate and edit the network configuration file for your chosen network interface. The file names and locations can vary based on your Linux distribution:
  • Debian/Ubuntu (using nano or vim): sudo nano /etc/network/interfaces
  • RedHat/CentOS (using nano or vim):
    bash sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
  1. Configure the IP Address:
    In the configuration file, modify the lines related to IP configuration. Replace the values with your desired static IP address, subnet mask, and gateway. For example:
   # Debian/Ubuntu
   iface eth0 inet static
       address 192.168.1.10
       netmask 255.255.255.0
       gateway 192.168.1.1
   # RedHat/CentOS
   DEVICE=eth0
   BOOTPROTO=none
   IPADDR=192.168.1.10
   NETMASK=255.255.255.0
   GATEWAY=192.168.1.1
  1. Set DNS Servers:
    Add DNS server addresses to the configuration file to enable hostname resolution. Add lines like DNS1 and DNS2:
   # Debian/Ubuntu
   iface eth0 inet static
       address 192.168.1.10
       netmask 255.255.255.0
       gateway 192.168.1.1
       dns-nameservers 8.8.8.8 8.8.4.4
   # RedHat/CentOS
   DEVICE=eth0
   BOOTPROTO=none
   IPADDR=192.168.1.10
   NETMASK=255.255.255.0
   GATEWAY=192.168.1.1
   DNS1=8.8.8.8
   DNS2=8.8.4.4
  1. Restart Networking:
    After editing the configuration file, restart the network service to apply the changes:
  • Debian/Ubuntu: sudo systemctl restart networking
  • RedHat/CentOS:
    bash sudo systemctl restart network
  1. Test Connectivity:
    Test the connectivity using the configured static IP address and verify that you can access resources on the network and the internet.

Keep in mind that the specific steps and file locations can vary depending on the Linux distribution and version you are using. Always double-check the documentation for your distribution to ensure accurate configuration.