74

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.

Zanna
  • 70,465
FastSloth
  • 741
  • 1
    Hi & Welcome to AU. I'm actually lost when you say Windows & Ubuntu on a separate partition. Because either it has to be a dual boot which will run separately or else it has to be a VM (virtual machine). Can you please elaborate on how both of these OS operates and configured?? :) – AzkerM May 21 '14 at 17:52
  • 1
    You WILL have problems with two simultaneously connected machines with the same MAC address, but not if they are running at different times. So your problem is probably in some other place, if I understand well (and even if you have the server in a VM, the VM will solve the MAC problem for you; each VM has its own unique MAC). – Rmano May 21 '14 at 18:08
  • See https://help.ubuntu.com/14.04/serverguide/network-configuration.html . The router doesn't see two computers ; it sees the same interface card (NIC) no matter which is running. – belacqua May 21 '14 at 19:24

5 Answers5

116

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.

Pang
  • 373
Dan
  • 6,753
  • 5
  • 26
  • 43
  • @dan08- I believe dns-nameservers is also needed here. I suggest you edit your answer. – chili555 May 22 '14 at 14:47
  • 24
    Restart eth0 with sudo ifdown eth0 && sudo ifup eth0 instead of the last command. – Kenny Evitt Jan 27 '15 at 04:45
  • In my env gateway ended with .254, not sure if this applies for everyone. Other than that this answer works for 14.14 – mau May 09 '15 at 15:59
  • 1
    Does not work by me, I still got DHCP IP. Sadly it is coming from a hybrid modem + router device, which does not have to feature to set static IP by MAC address. :S I might need to buy a router. :S According to ifdown eth0 the interface is not configured. – inf3rno Feb 28 '16 at 16:57
  • but now the network would start automatically – Allan Ruin Aug 10 '16 at 16:10
  • hi, in ubuntu16.04, you can't modify this configure file. you shall use network-manager ui or cli to modify it. thanks. – keniee van Aug 06 '17 at 23:27
10

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! :)

muru
  • 197,895
  • 55
  • 485
  • 740
8

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 https://help.ubuntu.com/lts/serverguide/network-configuration.html

0

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.
0

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 https://netplan.io/examples with a whole bunch of copy-paste configurations for the config.yaml file, which seem like a great approach for most cases.