To configure a static IP address on a Linux system, you will need to edit the network configuration files for the network interface that you want to assign the static IP address to. The specific steps and configuration files will vary depending on your Linux distribution and version.
Here are the general steps for configuring a static IP address on a Linux system:
ip
command to list the available network interfaces on your system:$ ip link show
The name of the network interface will be listed as eth0
, wlan0
, etc.
Find the network configuration file for the network interface. On most Linux systems, the network configuration files are located in the /etc/network
or /etc/sysconfig/network-scripts
directory. The name of the configuration file will usually be the name of the network interface with the .conf
or .ifcfg
extension (e.g., eth0.conf
, wlan0.ifcfg
).
Edit the network configuration file using a text editor. You will need to set the following options to configure the static IP address:
BOOTPROTO
: Set this option to static
to specify that you want to use a static IP address.IPADDR
: Set this option to the static IP address that you want to use.NETMASK
: Set this option to the network mask for the subnet that the IP address belongs to.GATEWAY
: Set this option to the default gateway for the network.Here's an example of a network configuration file that sets a static IP address of 192.168.1.100
with a network mask of 255.255.255.0
and a default gateway of 192.168.1.1
:
BOOTPROTO=static IPADDR=192.168.1.100 NETMASK=255.255.255.0 GATEWAY=192.168.1.1
Save the network configuration file and exit the text editor.
Restart the network interface to apply the changes. You can use the ifdown
and ifup
commands to bring the interface down and then back up:
$ sudo ifdown <interface> $ sudo ifup <interface>
Replace <interface>
with the name of the network interface that you want to restart (e.g., eth0
, wlan0
).
ping
command to test the connectivity to the default gateway and other devices on the network:$ ping <gateway> $ ping <IP address>
Replace <gateway>
with the default gateway IP address, and replace <IP address>
with the IP address of another device on the network.