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.
- Set IP address using command line:
Open the terminal and type the following command: - Use the command “sudo ifconfig
netmask “ - 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. - For example, configure the IP address of the eth0 interface as 192.168.0.100 with a subnet mask of 255.255.255.0.
- 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.
- 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: - iface
inet static
address
netmask is the name of the network interface, while and are the IP address and subnet mask to be configured respectively. - Save the file and restart the network service using the following command:
- 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.