How To Give Static Ip In Ubuntu Server

People are currently reading this guide.

Tired of Your Server Playing Hide-and-Seek on the Network? Assign it a Static IP!

Ever feel like your Ubuntu server is playing a never-ending game of hide-and-seek on your network? One minute it's there, responding to your pings with lightning speed, the next it's vanished without a trace, replaced by some cryptic DHCP-assigned gibberish. Fear not, fellow server wranglers! Today, we'll banish this digital disappearing act by assigning our server a static IP address.

How To Give Static Ip In Ubuntu Server
How To Give Static Ip In Ubuntu Server

But First, Why Go Static?

Think of a static IP as your server's permanent name tag at a network party. Everyone knows exactly where to find it, making remote access and configuration a breeze. This is especially crucial for servers that need to be accessed frequently or act as central hubs for other devices. Plus, with a static IP, you can say goodbye to scrambling to remember that random string of numbers your server decided to wear today.

QuickTip: Slow down when you hit numbers or data.Help reference icon

Conquering the Configuration Cavern: Editing the Netplan File

Now, let's grab our virtual pickaxes and head into the network configuration cavern. Our weapon of choice? The trusty nano text editor. Important Note: Always back up your configuration files before making changes. A typo here could leave your server as lost as a misplaced sock in a dryer.

Tip: Focus on sections most relevant to you.Help reference icon
  1. Unearthing the Netplan File: Open your terminal and type:
sudo nano /etc/netplan/01-netcfg.yaml

This will open the netplan configuration file, but wait! Where's the giant red "SET STATIC IP HERE" button? Relax, adventurer. We'll have to craft this magic ourselves.

The article you are reading
InsightDetails
TitleHow To Give Static Ip In Ubuntu Server
Word Count913
Content QualityIn-Depth
Reading Time5 min
Tip: Keep the flow, don’t jump randomly.Help reference icon
  1. Deciphering the Netplan Code: The netplan file uses YAML, a simple language that might look like hieroglyphics at first glance. But fear not! We only need to focus on a few sections.

  2. Slaying the DHCP Beast: Look for the line dhcp4: yes. This tells your server to request an IP address from a DHCP server (the network's leasing agent). Change this to dhcp4: no to declare our independence from DHCP's whims.

  3. Forging the Static IP Identity: Now for the fun part! Find the addresses section and add a line like this:

addresses: [192.168.1.100/24]

Replace 192.168.1.100 with your desired static IP address (make sure it's not already in use on your network) and /24 represents the subnet mask (usually 255.255.255.0 for home networks).

QuickTip: A careful read saves time later.Help reference icon
  1. Gateway secured! Optionally, you can add a line for the gateway (your network's router) under the gateway section:
gateway: 192.168.1.1

Remember to replace these example addresses with your own!

How To Give Static Ip In Ubuntu Server Image 2
  1. Exiting the Cavern Victorious: Once you've made your edits, save the file (Ctrl+O) and exit nano (Ctrl+X).

Applying the Changes: Let There Be Static IP!

Now that we've configured our static IP, it's time to make it official. Run the following command in your terminal:

sudo netplan apply

This command applies the changes you made in the netplan file.

Double-check your handiwork: Use the command ip addr show to verify that your server has adopted its new static IP address.

Content Highlights
Factor Details
Related Posts Linked25
Reference and Sources5
Video Embeds3
Reading LevelEasy
Content Type Guide
Frequently Asked Questions

Conquering Common Quandaries: A Static IP FAQ

  • How to find my current IP address? Use the command ip addr show in your terminal. Look for the IP address associated with your network interface (usually ens3 or eth0).

  • How to find my subnet mask? This can be a bit trickier. You can try using online tools or consult your network router's documentation. If you're stuck, a common subnet mask for home networks is 255.255.255.0.

  • How to find my gateway address? This is usually the IP address of your network router. You can check your router's documentation or web interface to find it.

  • How to connect to my server after setting a static IP? Use the new static IP address you assigned to your server when connecting via SSH or other remote access tools.

  • Oops! I messed up the configuration file! How do I fix it? Don't panic

How To Give Static Ip In Ubuntu Server Image 3
Quick References
TitleDescription
gitlab.comhttps://about.gitlab.com/handbook
netflix.comhttps://help.netflix.com
mit.eduhttps://ocw.mit.edu
mozilla.orghttps://developer.mozilla.org
freecodecamp.orghttps://www.freecodecamp.org

hows.tech

You have our undying gratitude for your visit!