How do you set an IP address in a Linux system?

In Linux systems, you can set up an IP address using either the command line or configuration files.

  1. Set IP address using command line:
    Open the terminal and type the following command:
  2. Use the command “sudo ifconfig netmask
  3. In the context, “” refers to the name of the network interface, such as eth0, wlan0, etc.; “” is the IP address to be set; and “” is the subnet mask of the network.
  4. For example, configure the IP address of the eth0 interface as 192.168.0.100 with a subnet mask of 255.255.255.0.
  5. Grant administrative privileges to configure the network interface eth0 with the IP address 192.168.0.100 and a subnet mask of 255.255.255.0.
  6. Setting IP address using configuration file:
    Open the terminal, edit the network configuration file (usually located at /etc/network/interfaces or /etc/sysconfig/network-scripts/ifcfg-), and add the following content:
  7. iface inet static
    address
    netmask
  8. is the name of the network interface, while and are the IP address and subnet mask to be configured respectively.
  9. Save the file and restart the network service using the following command:
  10. Restart the networking service using the command “sudo systemctl restart networking”.

Regardless of which method is used to set the IP address, a restart of the network service or a system reboot is required for the settings to take effect.

bannerAds