Notes – Static IP Ubuntu 16.04 LTS

Check your current IP via “ifconfig -a” or “ip addr“. Then edit the network configuration for the interface via “sudo nano /etc/network/ineterfaces“.

ifconfig -a
ip addr
sudo nano /etc/network/interfaces
root@ubuntu:~# ifconfig -a
ens33     Link encap:Ethernet  HWaddr 00:0c:29:50:97:bf
          inet addr:10.1.1.13  Bcast:10.1.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe50:97bf/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:838 errors:0 dropped:0 overruns:0 frame:0
          TX packets:142 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:58796 (58.7 KB)  TX bytes:19717 (19.7 KB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:160 errors:0 dropped:0 overruns:0 frame:0
          TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:11840 (11.8 KB)  TX bytes:11840 (11.8 KB)

root@ubuntu:~#
root@ubuntu:~# ip addr
1: lo: <;LOOPBACK,UP,LOWER_UP>; mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <;BROADCAST,MULTICAST,UP,LOWER_UP>; mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:50:97:bf brd ff:ff:ff:ff:ff:ff
    inet 10.1.1.13/24 brd 10.1.1.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe50:97bf/64 scope link
       valid_lft forever preferred_lft forever
root@ubuntu:~#
root@ubuntu:~# sudo nano /etc/network/interfaces

You’ll see the following and will need to edit the highlighted and add the static IP values.

  GNU nano 2.5.3               File: /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto ens33
iface ens33 inet dhcp



^G Get Help     ^O Write Out    ^W Where Is     ^K Cut Text     ^J Justify      ^C Cur Pos
^X Exit         ^R Read File    ^\ Replace      ^U Uncut Text   ^T To Spell     ^_ Go To Line
  GNU nano 2.5.3               File: /etc/network/interfaces                          Modified

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto ens33
iface ens33 inet static
        address 10.1.1.101
        netmask 255.255.255.0
        network 10.1.1.0
        broadcast 10.1.1.255
        gateway 10.1.1.1
        dns-nameservers 8.8.8.8 1.1.1.1



^G Get Help     ^O Write Out    ^W Where Is     ^K Cut Text     ^J Justify      ^C Cur Pos
^X Exit         ^R Read File    ^\ Replace      ^U Uncut Text   ^T To Spell     ^_ Go To Line

Ctrl + X, then save when prompted.

Lastly, we’ll need to restart network service via “sudo /etc/init.d/networking restart” or “sudo systemctl restart ifup@ens33

sudo /etc/init.d/networking restart
sudo systemctl restart ifup@ens33
root@ubuntu:~# sudo /etc/init.d/networking restart
[ ok ] Restarting networking (via systemctl): networking.service.
root@ubuntu:~#
root@ubuntu:~# sudo systemctl restart ifup@ens33
root@ubuntu:~#

If your IP address doesn’t change after restart of networking services, you can try to reboot the server or use the following command “sudo ifdown ens33 && sudo ip addr flush ens33 && sudo ifup ens33

sudo ifdown ens33 && sudo ip addr flush ens33 && sudo ifup ens33
Notes – Static IP Ubuntu 18.04 LTS Return to Notes list

Leave a Reply