There is a point to this story, but it has temporarily escaped my mind...
Contact Me MyFaceBook MyLinkedIn MyGitHub MyTwitter

How to set a Static IP in Ubuntu

Prior to 17.10

First, we need to shutdown the interface:

sudo ifdown eth0

To specify a static connection we need to change the Ethernet's interface configuration in /etc/network/interfaces:

iface eth0 inet static
address 192.168.0.101
gateway 192.168.0.254
netmask 255.255.255.0
dns-nameservers 8.8.8.8 8.8.4.4

If you are using IPv6 static addresses, add an additional block it /etc/network/interfaces:

iface eth0 inet6 static
address 2001:db8:ff01:6fe::1e3a
netmask 64
gateway 2001:db8:ff01:6fe::1
dns-nameservers 2001:4860:4860::8888 2001:4860:4860::8844

Keep in mind that only 3 name servers will end up in the resolv.conf file if you use both the IPv4 block and the IPv6 block above. This is an issue related to the libc resolver limitation of a maximum of 3 name servers…

Finally, restart the interface to put the new settings into effect:

sudo ifup eth0

17.10 and after

cat > /tmp/01-netcfg.yaml << EOF
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
     dhcp4: no
     dhcp6: no
     accept-ra: no
     addresses:
     - 192.168.1.222/24
     - fd35:cf89:7706:1e92::222/64
     gateway4: 192.168.1.1
     gateway6: fd35:cf39:7706:1e92:1
     nameservers:
       addresses:
       - 8.8.8.8
       - 8.8.4.4
       search:
       - lab.example.com
       - home.example.com
EOF
 
sudo mv /tmp/01-netcfg.yaml /etc/netplan/
sudo rm /etc/netplan/50-cloud-init.yaml

Once ready apply changes with:

sudo netplan --debug apply
Copyright © 2022 by Julian Easterling. SOME RIGHTS RESERVED.
Privacy Policy              Terms of Use             


Creative Commons License
Except where otherwise noted, content on this site is
licensed under a Creative Common Attribution-Share Alike 4.0 International License.


All of the opinions expressed on this website are those of Julian Easterling and
do not represent the views of any of my current and previous clients or employers in any way.

If you notice an error on the site or content that has not been properly attributed, bring
it to my attention using the contact page and I will endeavor to fix it as soon as I can.

I accept no responsibility or liability for any damages incurred by following any of
my advice or by using any of the information on my site or of those sites that I link to.