Setting up a static IP address is essential for maintaining consistent network connectivity, especially for servers. In Ubuntu, this can be achieved using the Netplan utility. In this tutorial, I’ll guide you through setting up a static IP address for your Ubuntu server.
Prerequisites:
An Ubuntu server.
Root or sudo access to the server.
Knowledge of your network’s gateway and preferred DNS addresses.
Step-by-Step Guide:
1. Login to your server:
First, ensure you’re connected to your server, either directly or via SSH.
2. Locate the netplan configuration:
Ubuntu’s netplan configuration files are stored in the /etc/netplan/ directory. Navigate to this directory and check the available configurations:
For the sake of this guide, our configuration file is named 00-installer-config.yaml
. Your filename might differ, so ensure to use the correct name in the following steps.
3. Edit the Configuration: Open the configuration file in a text editor of your choice, like nano
:
4. Enter the Static IP Configuration: Replace or modify the contents with the following template, making sure to adjust the interface name, gateway, and other parameters to fit your network setup:
network:
version: 2
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.64.217/24]
routes:
– to: 0.0.0.0/0
via: 192.168.64.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
Remember:
enp0s3
should be replaced with your server’s interface name (useip a
orifconfig
to find this).- Adjust the
/24
subnet mask if your network configuration is different. - Use the appropriate gateway and DNS addresses for your network setup.
5. Apply Your Changes: After saving and closing the file, apply the new configuration with:
6. Confirm the Configuration: Finally, verify that your static IP has been applied:
Your server should now proudly display the static IP address 192.168.64.217
.
Conclusion: Setting a static IP address on your Ubuntu server ensures reliable connectivity and reduces potential network issues. Make sure that this IP is either reserved or excluded from your network’s DHCP range to avoid any conflicts. Happy networking!