Assigning a static IP to Ubuntu Server 14.04 LTS

I've installed Ubuntu 14.04 LTS Server in my machine on a separate hard drive alonside my Windows 7 installation. The Windows OS has full network connectivity and internet access through the Ethernet, but the Ubuntu installation does not.

I have a hunch that this could be because my router which sees 2 different computers with the same MAC address, and the DHCP is not working. How do I assign the machine a common static IP so that both partitions can use my network? I am new to Ubuntu and I couldn't figure out which file to edit so that I can assign the static IP.

3

5 Answers

I'm not sure if this will solve your problem, but this answers your question and I think it's worth a shot.

To assign a static IP, you need to edit /etc/network/interfaces.

The interface will probably be called eth0.

The current entry will look something like:

auto eth0
iface eth0 inet dhcp

You will need to change this to:

auto eth0
iface eth0 inet static address 10.253.0.50 netmask 255.255.255.0 network 10.253.0.0 gateway 10.253.0.1 dns-nameservers 8.8.8.8

You will have to change the numbers around depending on your network, but you can find out the information by checking out ipconfig from Windows.

Make sure you choose an address outside the address space of the DHCP server.

Then restart networking sudo service networking restart. If that gives you trouble, reboot the machine.

6

Set your IP address changes in /etc/network/interfaces. Example:

auto eth0
iface eth0 inet static
address 192.168.1.128
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

Don't give your DNS configurations in /etc/resolv.conf because while we restart the server sometimes the configuration get erased.

So use vim /etc/resolvconf/resolv.conf.d/base (while updating configs in this it doesn't get removed)

example:

search (domain name)
nameserver 8.8.8.8
nameserver 8.8.4.4

Save and then restart your server, this fixed my static issue! :)

1

I found I had to include the dns settings:

auto lo enp0s25
iface lo inet loopback
iface enp0s25 inet static address 192.168.1.128 netmask 255.255.255.0 gateway 192.168.1.1 dns-search example.com dns-nameservers 8.8.8.8 8.8.4.4

See

3

Ubuntu 20.04 doesn't have /etc/network/interfaces and uses /etc/netplan/<config file>.yaml instead.

The .yaml config file is auto generated and can have many names but as long as it has .yaml extension it should work fine. Mine was 50-cloud-init.yaml on one machine, 00-installer-config.yaml on another.

To set the ip to 192.168.0.102, in /etc/netplan/<config file>.yaml:

network: ethernets: eth0: dhcp4: false addresses: [192.168.0.102/24] gateway4: 192.168.0.1 nameservers: addresses: [8.8.8.8,8.8.4.4,192.168.0.1] version: 2

You can look up what your current gateway is using ip route and put that in instead of 192.168.0.1

Also instead of eth0 you can have a different name for your network. If so, keep your network's name there.

Then sudo netplan apply

This kicked me out of SSH because I was SSHed through an old ip. I had to reboot the computer manually. Restarting router is a good idea too at this point to clear possible ip conflicts.

Also I found suggestions to edit the generator of this yaml file in /etc/cloud but I found no fool-proof docs how to do this. Instead, Canonical provides with a whole bunch of copy-paste configurations for the config.yaml file, which seem like a great approach for most cases.

Change the interfaces config:

$ sudo nano /etc/network/interfaces

Then replace the following configuration:

# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens160
iface ens160 inet static
# Enter your specific IP address address 192.168.1.130 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 8.8.8.8 8.8.4.4

Then trigger it via:

$ sudo service networking restart

or

$ sudo ifdown ens160; ifup ens160

If you encountered with an error, do the following command:

$ ip addr flush dev ens160

Also, you can reboot the os: sudo reboot


[NOTE]:

  • ens160 is my ethernet name, you can check it via $ ifconfig command.
  • This works and tested in Ubuntu 14.04 and 16.04.
  • Here's Ubuntu 18.04 configuration method.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like