Ubuntu Server - Does Not Run on Static Ip

Ubuntu Server - Does Not Run on Static Ip

I am totally new to ubuntu server(did not work with any server before). I have installed LAMP(apache2, mysql, php) on ubuntu server(16.04.1 LTS). It works all correctly. It has 192.168.0.22 Ip.

On other computers, there are windows 7 installed(192.168.0.45).

When i write ubuntu server's ip in windows browser, it works but when i write localhost on windows browser it does not work but it does work on ubuntu server.

So now I want to set custom/static ip on ubuntu server this 192.168.0.11 its totally does not work neither in ubuntu server browser or neither ping neither ping

my /etc/network/interfaces is something like this

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp2s0
iface enp2s0 inet dhcp

I dont have eth0. I did everything to find it but did not find

How i tried to change ubuntu server ip to static

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp2s0
iface enp2s0 inet static
   address 192.168.0.11
   netmask 255.255.255.0  #<-- random i dont know what should i have to write here
   gateway 192.168.0.1    #<-- random i dont know what should i have to write here
   network 192.168.0.10   #<-- random i dont know what should i have to write here
   broadcast 192.168.0.12 #<-- random i dont know what should i have to write here
   nameserver 8.8.8.8     #<-- random i dont know what should i have to write here

my /etc/hosts

127.0.0.1  localhost
127.0.1.1  web

#The following lines are desirable for IPv6 capable host
::1       localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Repeat I dont have etho

Command :

root@web: # ipconfig -a

enp0s25   Link encap:Ethernet hwaddr .......
          broadcast MULTICAST MTU:15000.....
           ... 0... 0...0 ..
           .................................
           .................................

enp2s0    Link encap:ethernet hwaddr .......
          inet addr:192.168.0.22 bcast :192.168.0.255 mask 255.255.255
          inet6 addr fe80::..:...
          ...........................
          ...........................
          ...........................

lo        link encap:local Loopback
          inet addr:127.0.0.1  Mask :255.0.0.0
          inet6 addr:  ::1/128 Scope:host
          UP LOOPBACK RUNNING  MTU :numbera
          rx pckts :228 bla bla bal
          ..........
          ..........

I have put almost all information. If you need any further information tell me. Ty for helping.

9

2 Answers

I suggest you amend the file /etc/network/interfaces to read:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp2s0
    iface enp2s0 inet static
    address 192.168.0.10
    netmask 255.255.255.0  
    gateway 192.168.0.181
    dns-nameservers 8.8.8.8

Get the system to re-read and use the changes:

sudo ifdown enp2s0 && sudo ifup -v enp2s0

The -v for verbose should produce some output that tells us if the address was given successfully. Test:

ping -c3 192.168.0.181
ping -c3 8.8.8.8
ping -c3 

If you get ping returns, you are all set.

8

You can use the following

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp2s0
    iface enp2s0 inet static
    address 192.168.0.10
    netmask 255.255.255.0  #depends on your network class of address
    gateway 192.168.0.1    #address of the server that allow you to connect internet or other networks.
    dns-nameservers 8.8.8.8     #domain names resolver 8.8.8.8 it's google's public dns

then

$ sudo touch /etc/network/interfaces.d/enp2s0

then

$ sudo ifdown enp2s0 && sudo ifup enp2s0
13

Your Answer

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

Maya Lin-Takahashi
Author

Maya Lin-Takahashi

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.