In today’s guide, we are going to see how to configure a static IP address on Ubuntu server 18.04/19.04. After installing Ubuntu 18.04/19.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.
If you are new to Linux you may consider reading Top 20 Basic Linux Most Used Commands for Newbies with Examples.
Method 1: Manually edit Network Configuration files
To get a Static Ip Address on Ubuntu server 18.04/19.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 220.127.116.11 and default gateway being 10.10.1.1.
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 18.104.22.168 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 tee /etc/resolv.conf <<EOF nameserver 22.214.171.124 nameserver 126.96.36.199 EOF
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
Method 2: Use Netplan YAML network configuration
On Ubuntu 18.04/19.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,188.8.131.52] 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