SystemMen - In this article, I will guide you through the static IP configuration on Ubuntu server 16. Using IP is a common requirement when you build your system, you need to manage your IP closely and clearly.
Check current configuration
You open the ssh window to Ubuntu machine, type the following command to check if the server is currently configured DHCP or static IP configuration. For example, my server has two interfaces, enp0s3 and enp0s8. I want to implement on enp0s8.
cat /etc/network/interfaces | grep enp0s8
As you can see in the image above, the interface is currently configured to IP through DHCP.
Set static IP for the interface
To set the static IP for the enp0s8 interface, type the following command to open the configuration file:
Type the following if you are a regular user:
sudo nano /etc/network/interfaces
The configuration file will open similar to the image below.
Now delete the following two lines in the file.
auto enp0s8 iface enp0s8 inet dhcp
Then, you copy the following code to the place just deleted 2 lines above.
auto enp0s8 iface enp0s8 inet static address 192.168.56.20 netmask 255.255.255.0 gateway 192.168.56.1 dns-nameservers 22.214.171.124 126.96.36.199
- 192.168.56.20: the static IP assigned to the interface.
- 255.255.255.0: netmask used for interface, this is /24.
- 192.168.56.1: gateway.
- 188.8.131.52 184.108.40.206: declare IP of DNS server, here we use DNS google.
After you finish adding, press
Ctrl + X -> press
y -> press
Enter. This will save the file.
Next you type the following command to flush the old IP, you must be careful at this step. If you were previously ssh over the old IP, after you run this command, you will be disconnected from ssh.
sudo ip addr flush enp0s8
Then, you run the command to restart the network service so that the interface can receive the new IP.
sudo systemctl restart networking.service
Now you can check the new IP:
With this tutorial, you were able to completely configure a static IP for a server running Ubuntu server 16.If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.
If you appreciate what we share in this blog, you can support us by:
- Stay connected to: Facebook | Twitter | Google Plus | YouTube
- Subscribe email to recieve new posts from us: Sign up now.
- Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
- Become a Supporter - Make a contribution via PayPal.
- Support us by purchasing Ribbon Lite Child theme being using on this website.
We are thankful for your support.