How to Set a Static IP on Ubuntu

Understanding Static IP Addresses

An IP address is a unique string of numbers separated by periods, serving as a digital label for devices on a network. It enables data transmission between devices, with routers using these addresses to direct traffic accurately.

DHCP vs. Static IP

  • Dynamic Host Configuration Protocol (DHCP): Automatically assigns IP addresses to devices on a network. This can lead to changing IP addresses, especially after reboots or lease expiration, causing potential connectivity issues.
  • Static IP: Permanently assigns a specific IP address to a device, ensuring consistency and eliminating the issues associated with DHCP.

Why Set a Static IP?

Setting a static IP address is beneficial for:

  • Consistent Network Access: Ensures devices like servers, printers, and other critical machines maintain the same IP address, preventing disconnections.
  • Simplified Troubleshooting: Makes it easier to diagnose and resolve network issues.
  • Enhanced Security: Prevents unauthorized IP address changes that could disrupt network security settings.

Methods to Set a Static IP on Ubuntu

Method 1: Configuring the Static IP Using CLI

Step 1: Identify Network Interface

  1. Open Terminal: Press Ctrl + Alt + T to open the terminal.
  2. List Network Interfaces: Use the ip command to list available network interfaces.
    ip link
    

    Look for your network interface name, such as enp0s3.

Step 2: Create Netplan Configuration File

Netplan is Ubuntu’s network management tool, using YAML files to configure network settings.

  1. Open Configuration File: Use a text editor to open or create the Netplan configuration file.
    sudo nano /etc/netplan/01-netcfg.yaml
    
  2. Edit Configuration File: Add or modify the file with your network interface details.
    network:
      version: 2
      ethernets:
        enp0s3:
          dhcp4: no
          addresses:
            - 192.168.1.100/24
          gateway4: 192.168.1.1
          nameservers:
            addresses:
              - 8.8.8.8
              - 8.8.4.4
    

    Replace enp0s3 with your interface name and adjust the IP address, gateway, and nameservers accordingly.

Step 3: Apply Configuration

  1. Save and Exit: Press Ctrl + XY, and Enter to save and exit Nano.
  2. Apply Changes: Use Netplan to apply the new configuration.
    sudo netplan apply
    
  3. Verify Configuration: Check if the IP address has been set correctly.
    ip a
    

Affordable VPS Hosting With Dracula Servers

Looking for reliable and budget-friendly Virtual Private Server (VPS) hosting? Look no further than Dracula Servers. Dracula Servers offers a range of VPS hosting plans tailored to meet diverse needs. With competitive pricing, robust performance, and a user-friendly interface, it’s an excellent choice for individuals and businesses alike.

Explore the Dracula Servers website to discover hosting solutions that align with your requirements and take your online presence to new heights with their affordable and efficient VPS hosting services.

Visit Dracula Servers and experience reliable VPS hosting without breaking the bank.

Method 2: Setting a Static IP Using GUI

Step 1: Open Network Settings

  1. Access Network Settings: Click on the network icon in the top-right corner of the screen, then select Settings.
  2. Open Wired Settings: In the network settings window, click on the gear icon next to the wired connection.

Step 2: Configure Static IP

  1. Switch to IPv4 Settings: Navigate to the IPv4 tab.
  2. Select Manual Configuration: Change the method from Automatic (DHCP) to Manual.
  3. Enter IP Details: Fill in the IP address, netmask, gateway, and DNS servers.

    Example:

    • Address: 192.168.1.100
    • Netmask: 255.255.255.0
    • Gateway: 192.168.1.1
    • DNS: 8.8.8.8, 8.8.4.4
  4. Save and Apply: Click Apply to save the changes.

Step 3: Verify Configuration

  1. Restart Network: Toggle the network connection off and on to apply changes.
  2. Check IP Address: Verify the new static IP address by checking the connection details or using the ip a command in the terminal.

Additional Tips for Network Configuration

Using Static IP for Wi-Fi Connections

Setting a static IP for Wi-Fi connections follows a similar process. Access the Wi-Fi settings and adjust the IPv4 configuration to Manual, then enter the desired IP details.

Troubleshooting Common Issues

  1. Incorrect Configuration: Double-check the YAML syntax and IP details.
  2. Network Conflicts: Ensure no other device on the network uses the same IP address.
  3. Firewall Settings: Adjust firewall settings if network connectivity issues persist.

Using NetworkManager for Advanced Configurations

NetworkManager provides advanced network configuration options through both CLI (nmcli) and GUI (nmtui). These tools offer flexibility for managing complex network setups.

Frequently Asked Questions (FAQ)

Why Should I Set a Static IP Address?

Setting a static IP address ensures consistent network access, simplifies troubleshooting, and enhances security by preventing unauthorized changes.

How Do I Revert to DHCP?

To revert to DHCP, edit the Netplan configuration file and set dhcp4: yes for the desired interface, then apply the changes with sudo netplan apply.

Can I Set a Static IP for Multiple Interfaces?

Yes, you can configure static IP addresses for multiple interfaces by defining each interface separately in the Netplan configuration file.

Conclusion

Setting a static IP address on Ubuntu provides stability and consistency for network connections. Whether you prefer using the CLI or GUI, this guide offers comprehensive steps to help you configure your Ubuntu system effectively. By following these methods, you can ensure your network settings remain unchanged, providing a reliable connection for your devices.

Check out More Linux Tutorials Here!

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
× Dracula Servers

Subscribe to DraculaHosting and get exclusive content and discounts on VPS services.