How to set a static ip address on Ubuntu

To set a static IP address on Ubuntu, you can follow these steps:

Set a static IP address on Ubuntu

Identify the network interface that you want to configure with a static IP address. You can use the ifconfig or ip addr show command to list the available interfaces. Typically, the primary network interface is named eth0 or ensX (where X is a number).

Edit the network configuration file: Open the network configuration file for editing using a text editor. In Ubuntu, the file is usually located at /etc/netplan/. For example, you can use the following command to open the file with the Nano editor:

sudo nano /etc/netplan/01-netcfg.yaml

Configure the static IP address: Inside the configuration file, you’ll see a YAML structure defining the network interface settings. Modify the file to specify the static IP address, subnet mask, gateway, and DNS servers. Here’s an example configuration:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      addresses: [192.168.0.10/24]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

Adjust the values according to your network configuration. Save the changes and exit the editor.

Apply the network configuration: Once you have saved the changes to the network configuration file, apply the new configuration using the netplan command:

sudo netplan apply

This will apply the static IP address and update the network settings.

Verify the static IP address: To verify that the static IP address has been set successfully, use the ip addr show or ifconfig command again and look for the interface you configured. The output should display the static IP address you specified.

That’s it! Your Ubuntu system should now have a static IP address configured on the chosen network interface. Remember to adapt the instructions to match your specific network settings and network interface names.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments