Static IP – Unable to Properly Set Static IP in Ubuntu 16.04

16.04networkingstatic-ip

I'm trying to setup a static IP on an interface in Ubuntu 16.04. It's for a local connection with no DHCP server or DNS configuration. I've tried doing it from the Edit Connections GUI as well as from the CLI and am not having much luck.

I've searched around and found several similar questions (Set static IP Ubuntu 16.04, etc), but cannot seem to get the right setup myself.

Here is where I am at… There are currently three devices connected to a switch. One configured at 1.51, one at 1.20, and this 16.04 system I'm trying to configure for 1.49. Both 51 and 20 are communicating fine. I've switched out cables and tried different ports… so I know it's not a physical issue. And, in fact, one of the other systems on this switch is an Ubuntu 14.04 with an interface setup identically, but the IP is 51. The only problem here appears to be the Ubuntu 16.04 system.

16.04 /etc/network/interfaces file:

# interfaces(5) file used by ifup(8) and ifdown(8)
# The loopback network interface
auto lo
iface lo inet loopback

# Primary network interface
auto enp4s0
#iface enp4s0 inet dhcp
iface enp4s0 inet static
    address 192.168.1.49
    netmask 255.255.255.0
    gateway 192.168.1.1

$ ifconfig
enp4s0    Link encap:Ethernet  HWaddr f4:8e:38:e7:39:31  
      inet addr:192.168.1.49  Bcast:192.168.1.255  Mask:255.255.255.0
      inet6 addr: fe80::f68e:38ff:fee7:3931/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:258 errors:0 dropped:0 overruns:0 frame:0
      TX packets:2123 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:28821 (28.8 KB)  TX bytes:208448 (208.4 KB)

Everything looks fine. But pings fail. Can't ping in or out. The most interesting thing to me is the netmask when looking at the interface from the GUI. If I go to "Edit Connections…" from the network icon on the top right and edit this interface, it shows the following:

Address: 192.168.1.49
Netmask: 24
Gateway: 192.168.1.1

A netmask of "24"? That doesn't make any sense… but things look fine from ifconfig from the CLI.

I'm out of ideas. Should be simple…?

Thanks.

EDIT 1:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    100    0        0 enp4s0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 enp4s0
192.168.1.0     0.0.0.0         255.255.255.0   U     100    0        0 enp4s0

Best Answer

You have not declared DNS nameservers. I suggest you amend to:

# interfaces(5) file used by ifup(8) and ifdown(8)
# The loopback network interface
auto lo
iface lo inet loopback

# Primary network interface
auto enp4s0
#iface enp4s0 inet dhcp
iface enp4s0 inet static
    address 192.168.1.49
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 8.8.8.8 192.168.1.1

Restart the interface:

sudo ifdown enp4s0 && sudo ifup enp4s0

Ping:

ping -c4 www.ubuntu.com

If you get ping returns, you are all set.

Related Question