11

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
linsek
  • 222
  • 2
    A netmask of 255.255.255.0 is equivalent to /24 (just as 255.255.0.0 is /16, or 255.255.255.128 is /28). What's the output of route -n? – muru Jun 07 '16 at 17:17
  • Added output to post – linsek Jun 07 '16 at 17:23
  • I'm assuming you can't, but for the sake of troubleshooting, can you ping 192.168.1.1? –  Jun 07 '16 at 19:03
  • 192.168.1.1 doesn't actually exist. There are only 3 devices plugged into this switch. 20, 51, and 49. – linsek Jun 08 '16 at 15:17

3 Answers3

11

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.

chili555
  • 60,188
  • This appears to be the solution. The ping to ubuntu.com obviously doesn't work on a local network of 3 systems, but the definition of the dns-nameservers is what needed to occur for the interface to come up properly. – linsek Jun 09 '16 at 14:36
0

Your issue could very much be connected to the networkmanager getting into your configurations. Since you're using static IP's and don't want them to be changed automatically you don't really need the networkmanager.

Did you try deactivating it completly with sudo service network-manager stop and then try your connection again.

Ziazis
  • 2,174
0

If you are looking for manual bridge settings (e.g. for virtual machines):

Follow the instructions on Ubuntu help about setting up a bridge

  1. In your /etc/network/interfaces - comment out the network interface that will be bridged.
  2. Put all static setting under br0 (e.g. iface br0 inet static then address, network, gateway, nameserver etc.)
  3. Clear arp: ip addr flush enp2s0 (replace enp2s0 with your interface)
  4. Restart networking: systemctl restart networking

Step 3 is important when going from dhcp to static. It is not mentioned in the manual but your DNS and gateway may not work without it...

Good Luck!

QT-1
  • 1,402