Setting a static IP address on a Linux system can be useful in certain situations, such as when you need to access a specific network or device consistently. While most systems are configured to use dynamic IP addresses (DHCP) by default, temporarily setting a static IP address is a straightforward process. In this article, we will walk you through the steps to set a static IP address on a Linux system.
Step 1: Open the Terminal
The first step is to open a terminal window on your Linux system. You can do this by searching for the terminal application in your system’s application menu or by pressing Ctrl+Alt+T.
Step 2: Check the current network configuration
Before setting a static IP address, it’s important to know the current network configuration of your system. You can do this by running the following command in the terminal:
ip a
This command will show you information about your network interfaces, including the current IP address and subnet mask.
Step 3: Edit the network configuration file
Next, you will need to edit the network configuration file for the network interface you want to assign a static IP address to. The configuration file is usually located in the /etc/netplan
directory. You can edit the configuration file using a text editor such as nano or vim. For example, to edit the configuration file for the default network interface eth0
, run the following command:
sudo nano /etc/netplan/50-cloud-init.yaml
Step 4: Set a static IP address
Inside the configuration file, you will see a section that defines the network configuration for the interface. To set a static IP address, you will need to add the addresses
and gateway4
fields. For example:
network:
ethernets:
eth0:
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
In this example, we have set the static IP address to 192.168.1.100
with a subnet mask of /24
and the gateway address to 192.168.1.1
. You can also specify DNS servers by adding the nameservers
field.
Step 5: Apply the network configuration
Once you have edited the network configuration file, save the changes and exit the text editor. To apply the new network configuration, run the following command in the terminal:
sudo netplan apply
This command will apply the changes you made to the network configuration file and assign the static IP address to the specified network interface.
Step 6: Verify the static IP address
To verify that the static IP address has been successfully set, you can run the ip a
command again in the terminal. You should see the new static IP address displayed for the network interface you configured.
In conclusion, setting a static IP address on a Linux system is a simple process that can be useful in certain situations. By following the steps outlined in this article, you can easily assign a static IP address to a network interface on your Linux system.