ubuntu server - does not run on static ip

13,592

Solution 1

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 www.ubuntu.com

If you get ping returns, you are all set.

Solution 2

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
Share:
13,592

Related videos on Youtube

Phoenix
Author by

Phoenix

I just turned 19 years old. Although I was born, raised in India, I live in the Italy. I have lived and traveled to many different places. My hobbies Programming, Porgramming, and really anything Programming. I would like to know EVERYTHING about computer science. My favorite subjects in school growing up are Informatic, Matematic, English. In school, i have learned c++ OOP, java that i love a lot.. and php, js(jquery), css, html learning alone with also small help of [SO] in chat.1 Skype : phoenix.h4cker whatsapp: privacy Fb: facebook.com/Phoenix_does_not_exists

Updated on September 18, 2022

Comments

  • Phoenix
    Phoenix over 1 year

    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 www.google.com

    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.

    • Phoenix
      Phoenix almost 8 years
      oohh sorry.. it works correcty with 192.168.0.22 which is server ip(this ip is dafualt bu server installation), this ip work also on windows. I want to have this server ip 192.168.0.11
    • Phoenix
      Phoenix almost 8 years
      @Arronical yes i did
    • user4556274
      user4556274 almost 8 years
      As Arronical notes, your network and broadcast lines are incorrect. network would be 192.168.0.0 and broadcast 192.168.0.255, but you can just omit them instead.
    • Phoenix
      Phoenix almost 8 years
      so should i do like this auto enp2s0 iface enp2s0 inet static address 192.168.0.10 netmask 255.255.255.0 gateway 192.168.0.1 network 192.168.0.0 broadcast 192.168.0.255 nameserver 8.8.8.8 and getway ? should i add ?
    • Phoenix
      Phoenix almost 8 years
      @user4556274 should i configure/etc/hosts ?
    • user4556274
      user4556274 almost 8 years
      /etc/hosts is used for local name resolution. It is not relevant to the specific question of setting a static IPv4 address.
    • Phoenix
      Phoenix almost 8 years
      ok last thing, i want to be clear should i do like this auto enp2s0 iface enp2s0 inet static address 192.168.0.10 netmask 255.255.255.0 gateway 192.168.0.1 network 192.168.0.0 broadcast 192.168.0.255 nameserver 8.8.8.8
  • Phoenix
    Phoenix almost 8 years
    its work but i am not able to connect to the network (ping google.com)
  • Phoenix
    Phoenix almost 8 years
    it is not connected to internet now.. what i do ?
  • user4556274
    user4556274 almost 8 years
    Make sure that the gateway line gives your actual gateway IPv4 address. If you don't know your gateway address, but your windows machines have internet connectivity, run ipconfig on one of the windows machines to see what the gateway address is.
  • Phoenix
    Phoenix almost 8 years
    gateway predefined 192.168.0.181
  • Phoenix
    Phoenix almost 8 years
    I tried everything but does not work :(
  • chili555
    chili555 almost 8 years
    What do other devices, Windows computers, iPads, iPods, etc., on the same network show as the gateway?
  • Phoenix
    Phoenix almost 8 years
    my windows pc shows me 192.168.0.181 and i check on server using netstat -rn it is showing me same 192.168.0.181
  • Phoenix
    Phoenix almost 8 years
    server let me use custom ip but it is not acessing the internet... i use command ping www.google.com but does not do anything
  • chili555
    chili555 almost 8 years
    192.168.0.181 is the gateway address on the Windows PC, Is the correct? The gateway?
  • Phoenix
    Phoenix almost 8 years
    yes it is 192.168.0.181
  • Phoenix
    Phoenix almost 8 years
    gateway 192.168.0.118 ? is it 181 ?
  • chili555
    chili555 almost 8 years
    Oops! Cleaning my bifocals now! Editing answer next! Sorry.
  • Adel Kihal
    Adel Kihal almost 8 years
    try route -n and past the output
  • Phoenix
    Phoenix almost 8 years
    why didn't you write network and broadcast ?
  • chili555
    chili555 almost 8 years
    It's not needed. Is it working as expected now?
  • Phoenix
    Phoenix almost 8 years
    i tried with sudo ifdown enp2s0 && sudo ifup -v enp2s0 -v verbose gives me strange result rtnetlink answers : Cannot assign requested address Parsing file /etc/network/interfaces.d/enp2s0......... after it i reboot then i tried ping -c3 192.168.0.181 3 packects transmitted, 3 ercived, 0% loss, time 2003ms then i try ping -c3 8.8.8.8 rslt 3 packets transmitted, 0 recived , 100% packet loss.. then i try with ping -c www.ubuntu.com result is ping:unknow host www.ubuntu.com same thing i tried with google same result i got. I dont know whats wrong is ?
  • Phoenix
    Phoenix almost 8 years
    i found one thing in resolv.conf nameserver 192.168.0.10 serach comanpyname.local btw i want set address 192.168.0.11 not 192.168.0.10
  • Adel Kihal
    Adel Kihal almost 8 years
  • chili555
    chili555 almost 8 years
    I don't understand. Are you saying that you included -v verbose and an actual part of the command? That's not what I suggested.
  • Phoenix
    Phoenix almost 8 years
    oops sorry i convinced that is in code... sorry btw i have solved problem using different address, i do not what problem had with 192.168.0.11. i changed to 192.168.0.50.
  • Phoenix
    Phoenix almost 8 years
    ok. i did. ty for helping. i have one more question My server is running on 192.168.0.50 on LAN from my workstation. But now i want to access it from my house