In today’s guide, we are going to see how to configure a static IP address on Ubuntu server 22.04|20.04|18.04. After installing Ubuntu 22.04|20.04|18.04 Server or Desktop, the default setting it to obtain an IP address automatically via DHCP server. This means that you will have to configure a Static IP address Manually.
Method 1: Manually edit Network Configuration files
To get a Static Ip Address on Ubuntu server 22.04|20.04|18.04, you’ll edit interfaces configuration file located at /etc/network/interfaces. You can use vi/vim editor or nano editor for this purpose.
In this example, we’ll use vim editor and configure our server to use the IP address of 10.10.1.5, netmask 255.255.255.0, dns server 8.8.8.8 and default gateway being 10.10.1.1.
Open /etc/network/interfaces
sudo vim /etc/network/interfaces
If you prefer nano editor, use:
sudo nano /etc/netwok/interfaces
Then add the following lines replacing with your IP information.
auto eth0
iface eth0 inet static
address 10.10.1.5
netmask 255.255.255.0
dns-servers 8.8.8.8
gateway 10.10.1.1
Save the configuration changes and quit. You can also update DNS server settings at runtime by adding the lines inside /etc/resolv.conf file.
$ sudo vim /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
For the changes to take effect, restart your network daemon by
sudo ifdown eth0 && sudo ifup eth0
Don’t forget to replace eth0 with your network card name.
Check that you have an ip address on eth0 interface by typing
$ ifconfig -a
## OR
$ ip addr
If you cannot see ip address, gateway, and netmask info, restart your computer. Just type the command reboot on the terminal
sudo reboot
Method 2: Use Netplan YAML network configuration
On Ubuntu 22.04|20.04|18.04, you can use Netplan which is a YAML network configuration tool to set static IP address.
This configuration assumes your network interface is called eth0. This may vary depending on your working environment.
Create a network configuration file.
sudo nano /etc/netplan/01-netcfg.yaml
Then configure like below.
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
# Ser IP address & subnet mask
addresses: [10.10.1.5/24]
# Set default gateway
gateway4: 10.10.1.1
nameservers:
# Set DNS name servers
addresses: [10.10.1.1,8.8.8.8]
dhcp6: no
When done making the changes, save the configuration file and apply your network settings.
sudo netplan apply
To confirm your network settings, use the command:
$ ip addr
If you don’t need IPv6, it’s possible to disable it like follows.
echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
Other Tutorials that you may Like
- How To Customize Bash on Linux with Bash-it
- Best Linux Books for Beginners & Experts
- Top Best Android Programming Books
- Best Arduino and Raspberry Pi Books For Beginners
- Best CCNA R&S (200-125) Certification Preparation Books
- Best CCNA Security (210-260) Certification Study Books
- Best LPIC-1 and LPIC-2 certification study books