How to Configure a Static IP Address on Ubuntu

How to Configure a Static IP Address on Ubuntu

To set a static IP address on Ubuntu, you can follow the steps below. This example assumes Ubuntu 20.04; please adjust the steps accordingly for your specific Ubuntu version.

1. Identify Network Interface:

  1. Check Network Interfaces:
    • Open a terminal and run the following command to find your network interface name (typically eth0 or enpXsX):
      ip a

2. Set Static IP Address:

  1. Edit Netplan Configuration File:
    • Open a text editor using the following command (you can use nano or any text editor of your choice):
      sudo nano /etc/netplan/00-installer-config.yaml
  2. Edit Netplan Configuration:
    • Edit the file content as follows:
      network:
        version: 2
        renderer: networkd
        ethernets:
          your_interface_name: # Add your interface name here (e.g., eth0)
            dhcp4: no
            addresses: [your_static_ip/your_subnet_mask]
            gateway4: your_gateway
            nameservers:
              addresses: [your_dns_server]
    • Fill in the variables:
      • your_interface_name: Your network interface name.
      • your_static_ip: Your desired static IP address.
      • your_subnet_mask: Subnet mask.
      • your_gateway: Default gateway.
      • your_dns_server: DNS server’s IP address.
  3. Apply Netplan Configuration:
    • Apply the Netplan configuration by running:
      sudo netplan apply

3. Verify Network Settings:

  1. Check Network Settings:
    • Verify the network settings using the following command:
      ip a
    • Ensure that your network interface lists the new static IP address.
  2. Check Internet Connection:
    • Test the internet connection using a web browser or the ping command:
      ping google.com
    • If the ping is successful, your internet connection is working correctly.

By following these steps, you can set a static IP address on Ubuntu. Note that you may need to restart network services or the network interface for the changes to take effect.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.