I am a new with Linux, having years experience with Windows servers/desktops and am having issues setting a static IP. I am using a method used for previous versions of Ubuntu, which doesn't seem to work with 16.04
I have used the command sudo nano /etc/network/interface and added the following
iface enp0s25 inet static
address 10.10.8.2
netmask 255.255.0.0
gateway 10.10.1.1
dns-nameservers 8.8.8.8 8.8.4.4I have rebooted the system and the Ethernet is pretty much dead, ping doesn't work at all. I have tried to modify /etc/NetworkManager/NetworkManager.conf and made the following changes
#dns=dnsmasq (comment out the dnsmasq)
[ifupdown]
managed=true (changed from false)With this I can get Ethernet to work sporadically, however it eventually fails.
I have tried this configuration on two other machines plus a virtual machine as well and all have the same results. I can confirm these settings work fine when I install Windows on any of these machines. As well when I let DHCP auto configure, everything works fine no issues.
I figure I am missing something here, setting up a static IP should not be difficult at all.
39 Answers
I had the same problem and this was my solution:
sudo nano /etc/network/interfacesand paste (altering for your network) this under # The primary network interface:
auto enp0s25
iface enp0s25 inet static
address 192.168.0.16
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 8.8.4.4 8.8.8.8You can get correct interface name using Terminal command ifconfig -a on ubuntu 16.04 or ip address on 18.04+
Shutdown your Virtual Machine and then!!! Go to network settings and click on refresh MAC address button a few times :)
and start your VM and you should get internet!
UPDATE 20.02.2019
For ubuntu 18.04+ you need to edit this file
/etc/netplan/50-cloud-init.yaml
network: ethernets: enp0s3: addresses: [192.168.0.55/24] gateway4: 192.168.0.1 dhcp4: no nameservers: addresses: [1.1.1.1,8.8.8.8] optional: true version: 2 4 Setting the static IP address as above in the accepted answer here works, but one has to flush the old IP addr setting and then restart networking.service:
sudo ip addr flush enp0s25
sudo systemctl restart networking.serviceThen verify it is correct:
ip add 3 # interfaces(5) file used by ifup(8) and ifdown(8)
# auto lo
# iface lo inet loopback
auto enp2s0
iface enp2s0 inet static address 172.16.9.124 netmask 255.255.240.0 gateway 172.16.0.9
dns-nameservers 8.8.8.8 2 sudo vim /etc/network/interfaces
auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.1.10 gateway 192.168.1.1 netmask 255.255.255.0 dns-nameservers 8.8.8.8sudo ifdown eth0 && sudo ifup eth0
I had the same problem and the solution "was" simply... for me, at least.
auto ens160
iface ens160 inet static
address 172.31.0.164/22
netmask 255.255.252.0
gateway 172.31.0.2
network 172.31.0.0
broadcast 172.31.3.255
dns-nameservers 172.31.0.21 172.31.0.18
#Add internal route
up route add -net 172.16.168.0/21 gw 172.31.0.20 dev ens160And, create an empty file with the name of the network interface in:
~$ touch /etc/network/interfaces.d/ens160It works...
I had the same problem and this was my solution:
Remove all empty lines at the end of the file /etc/network/interface.
If your server is showing that old IP as well as new assigned IP, simply restart your server. It will automatically flush old IP and persist the new one.
And if you don't want to restart your server, use this command:
sudo ip addr flush <your-interface-here>
Run this simple commands to see if your network interface(s) are set to come up when the machine boots / restarts.
grep "auto" /etc/network/interfacesIf no lines are printed to standard output, then open /etc/network/interfaces with a text editor (vi, nano, sed) and hopefully you will see something similar to the image below below.
Obviously, if grep did not return any lines to the terminal window, the format of your /etc/network/interfaces cannot be very similar at all. :-) However, follow the format of the auto lines.
auto lo
(Loopback configuration follows)
.
.
.
auto enp0s3
(primary interface configuration follows)
.
.
.====================
Now, on your machine.
auto yourInteraceNameHere
(your interface configuration follows)
.
.
.Don't know which interface names are available? Run this command.
ifconfig -aThe following command will return just the names of the network interfaces.
ifconfig -a | grep encap | awk {'print $1'} I used to set static IPs on my Ubuntu machines and then I noticed that I can just assign the IP address using my router. This may be the simplest solution. Just log in to your router, find the attached devices, and assign the IP address there.