Comments on Linux Basics - Set a Static IP on Ubuntu

Set a static IP on Ubuntu. All Ubuntu versions, from Ubuntu 22.04, and Ubuntu 20.04 down to Ubuntu 12.04, are covered in this tutorial. The guide explains setting a static IP on an Ubuntu system from the command line. It covers the network configuration for all recent Ubuntu versions and includes instructions to configure a static IP address, set the hostname, and configure name resolving.

36 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: Pilgrim

This command is deprecated on new debian and ubuntu:

/etc/init.d/networking restart

solution is a use command:

ifdown eth0 && ifup eth0

See #565187 netbase: Command deprecated and not explained

By: Anonymous

Bless you.  I saw that error and was noticing I had to completely restart to get the command to take.  I was not liking that and once I scrolled down to see if someone saw the same, I found your post.  Thank you so much!

By: Katz

What´s the ubuntu version, 11.10 or 12.04?

By: Freaki

I dunno about you but I don't like using the resolv.conf, I prefer to set the the nameserver to read my routers, and typically I'll use google's 8.8.8.8 or 8.8.4.4

 Heres a small guide I found if anyone is interested.

 http://ubuntuserverhelp.com/setting-up-a-static-ip/

By: Ranting

I used to use the command line method before Ubuntu 12.04 but now prefer the network manager method of setting a static IP.

This is only because after using this method then opening the connection manager to check what was showing (I know I could have checked on cli but dont like to be limited!) all the settings were reset to dhcp and my modifications were reset!

I didn't really fancy removing the network manager. Anybody else feel like they are being forced to use graphical methods more and more with newer Ubuntu releases?

By: Ranting

These instructions are slightly dated now and a lot of other instructions I'm seeing fail to address Network Manager managing the connection.
 
This article about setting a static IP in Ubuntu the proper way was very useful for me.
 
It's useful to note that the instructions on many sites and askubuntu answers do not apply to wireless devices!
 

 

 

By: Anonymous

Hmm any idea why you don't just do everything within the /etc/network/interfaces configuration folder like here: http://draalin.com/setting-up-a-static-ip-address-in-ubuntu/

 Or does it make more sense to actually split things up like you did within the resolv.conf and interfaces configuration folder?

By: brubakes

Just what I needed.  Thanks!

By: Chad

Hey this is not working on 14.04 Server Edition.

 

auto eth0iface eth0 inet static        address 173.244.42.82        netmask 255.255.255.240        gateway 173.244.42.81        # dns-* options are implemented by the resolvconf package, if installed        dns-nameservers 8.8.8.8

 

 

resolv.conf

 

nameserver 8.8.8.8nameserver 8.8.4.4

ifconfig

 

eth0      Link encap:Ethernet  HWaddr 00:25:90:3a:c2:36            inet addr:173.244.42.82  Bcast:173.244.42.95  Mask:255.255.255.240          inet6 addr: fe80::225:90ff:fe3a:c236/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:406 errors:0 dropped:174 overruns:0 frame:0          TX packets:182 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:40001 (40.0 KB)  TX bytes:28133 (28.1 KB)          Interrupt:16 Memory:fb5e0000-fb600000

By: till

It is working fine fro me on Ubuntu 14.04 server. Your ifconfig output shows that the IP settings got applied correctly. If you have problems with your IP setup, then please post in the forum to get help.

By: shabeer ahmad

i have followed the above procedure for setting up interfaces of my ubuntu 14.04 for my eth0 interface not showiing ip address after giving ifconfig command

By: TempleClause

You should specify what to do for version 14.04... 

For me it's unclear what to do since < 14.04 and > 14.04 does not match 14.04 in either case....

By: anonymus

Thanks very very match my friend!! This issues it's verry helpfulyy.

By: Mukund

Hi,

Can you guide me to set the static IP in Ubuntu 16.04

By: till

The instructions above are valid for Ubuntu 16.04 as well.

By: ilayaraja

I changed my IP in my ubuntu by using this method.

thanks.

By: sanwarul hoq

Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?... any kind of talk will ....

By: Anonymous

I did exactly as instructed, and did not get the desired result, in fact, nothing changed!

By: JonhDevNet

I also tried in version 16.04 but did not work.

I will keep trying.

By: Lucas

Before I ask, I would just like to let you know this is a great and detailed article and it taught and helped me so much. I am running Ubuntu 16.04, and followed all the steps. But I cannot find "eth0      Link encap:Ethernet  direcciónHW 00:33:27:46:2v:34

          Direc. inet:192.168.1.101  Difus.:0.0.0.0  Másc:255.255.255.0 ..."

The closest thing I can find is "eth0      Link encap:Ethernet  HWaddr 00:23:5a:18:18:ab  

          inet addr:192.168.1.114  Bcast:192.168.1.255  Mask:255.255.255.0

          UP BROADCAST MULTICAST  MTU:1500  Metric:1

"

Also, I could not access the internet until I disconnected from the Ethernet network! Is this normal?

By: Tom S

Thanks

By: Ratboy

hi, i tried this to but now my internet does't work anymore. if i do ifconfig i dont get that anymore  eth0      Link encap:Ethernet  direcciónHW 00:33:27:46:2v:34

          Direc. inet:192.168.1.101  Difus.:0.0.0.0  Másc:255.255.255.0

and befor i did get 

lo link encap (and a lot more)now i only get that.

can it be that my internet doesn't use eth0 but ens160?

 

 

By: Steffen

This doesn't work anymore when you're on a version of Ubuntu that uses systemd.

By: till

The tutorial works fine on Ubuntu versions with systemd, use the commands that are labeled for "Ubuntu 14.04 and newer" which show you how to restart networking with systemd.

By: Pedromiguel Pinto

En Ubuntu 16.04 existe un bug y es que no basta con reiniciar la interfaz de red, es necesario reiniciar el servidor para que tope los cambios en la interfaz, recomiendo sea cual sea la versión y si es posible reiniciar el sistema operativo después de modificar la interfaz de red.

Saludos

By: TiTex

why not just use nmcli or nmtui ?

By: Jason

The suggested steps for Ubuntu 16.04 do not work. Nothing changes...

By: till

The steps work fine here on Ubuntu 16.04, just verified that. If nothing changes on your server then you might have a typo somewhere. You might also try to restart the system to apply the changes when you are sure that you have no typos in the config.

By: Tech Gii

Using netplan I could not create a bridge for kvm virtulization.  Request for a small tutorial on this.  Its really sad that after years of experience in Linux,  I could not use netplan may be its complex or I do not know exact things.

 

By: tontze

Is there a tutorial how to setup static wifi with netplan in ubuntu server 17.10 ? 

By: Jurek

Final 18.4 Ubuntu server adds clouds to network configuration. What is the relation between cluster configuration files in /etc/cloud/cloud.cfg.d and /etc/netplan?

By: Mr Panda Sauce

It sucks that Ubuntu changed its networking infrastructure. I wish they kept the /etc/networking.d restart. that way new users could also learn about it. now its based on yaml >:

By: sethgwapo

wow this is cool thanks for sharing! xD

By: allzz

Nice article! Clear and concise, very helpful! Thanks!

By: zenadm1n

Instead of "apply" run the following to check your syntax with auto-rollback the configuration.

$ sudo netplan try

By: Max

In netplan, the filename doesn't matter.  It  just needs to be in the correct directory and end in .yaml.  Any conficts should be removed, so if you are creating a static IP and the existing yaml file is for DHCP, just rename the prior, existing, file so it doesn't end in .yaml.  Create the new file ... I like to use the filename template of

`$ ls /etc/netplan/enp*/etc/netplan/enp3s0-static.yaml/etc/netplan/enp7s0f0-SAN-static.yaml.disable/etc/netplan/enp7s0f1-mgnt-static.yaml.disable`so that the filename says which device, which LAN and if it is static or dhcp.