Set static IP Ubuntu












53















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


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










share|improve this question

























  • the only thing I notice and it may have just been a typo here but I would change the Dns-nameservers to dns-nameservers probably not going to do anything to solve this issue but may stop other issues from happening

    – John Orion
    May 2 '16 at 0:20











  • Dns-nameservers is acceptable syntax wise so it shouldn't be an issue. When it was working with DHCP, did you run an ifconfig to check the interface name or did you assume it was enp0s25? Also do you have an auto enp0s25 at the top of your config file? If you don't its possible that the interface is just not coming up on boot.

    – Andrew
    May 2 '16 at 0:30











  • Please edit your question and post the exact content of your /etc/network/interfaces file. While editing your message, highlight the text of this file, then click on the {} code link on the top of the message editor so that it will properly format the text making it easier for us to read the content. Also do execute this command ip address and perform the same steps to {} (code format) that output.

    – L. D. James
    May 2 '16 at 4:05
















53















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


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










share|improve this question

























  • the only thing I notice and it may have just been a typo here but I would change the Dns-nameservers to dns-nameservers probably not going to do anything to solve this issue but may stop other issues from happening

    – John Orion
    May 2 '16 at 0:20











  • Dns-nameservers is acceptable syntax wise so it shouldn't be an issue. When it was working with DHCP, did you run an ifconfig to check the interface name or did you assume it was enp0s25? Also do you have an auto enp0s25 at the top of your config file? If you don't its possible that the interface is just not coming up on boot.

    – Andrew
    May 2 '16 at 0:30











  • Please edit your question and post the exact content of your /etc/network/interfaces file. While editing your message, highlight the text of this file, then click on the {} code link on the top of the message editor so that it will properly format the text making it easier for us to read the content. Also do execute this command ip address and perform the same steps to {} (code format) that output.

    – L. D. James
    May 2 '16 at 4:05














53












53








53


17






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


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










share|improve this question
















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


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







networking network-manager dns dhcp ip






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 8 '18 at 18:57









lewis4u

2,42331530




2,42331530










asked May 1 '16 at 23:34









TeeStarTeeStar

368135




368135













  • the only thing I notice and it may have just been a typo here but I would change the Dns-nameservers to dns-nameservers probably not going to do anything to solve this issue but may stop other issues from happening

    – John Orion
    May 2 '16 at 0:20











  • Dns-nameservers is acceptable syntax wise so it shouldn't be an issue. When it was working with DHCP, did you run an ifconfig to check the interface name or did you assume it was enp0s25? Also do you have an auto enp0s25 at the top of your config file? If you don't its possible that the interface is just not coming up on boot.

    – Andrew
    May 2 '16 at 0:30











  • Please edit your question and post the exact content of your /etc/network/interfaces file. While editing your message, highlight the text of this file, then click on the {} code link on the top of the message editor so that it will properly format the text making it easier for us to read the content. Also do execute this command ip address and perform the same steps to {} (code format) that output.

    – L. D. James
    May 2 '16 at 4:05



















  • the only thing I notice and it may have just been a typo here but I would change the Dns-nameservers to dns-nameservers probably not going to do anything to solve this issue but may stop other issues from happening

    – John Orion
    May 2 '16 at 0:20











  • Dns-nameservers is acceptable syntax wise so it shouldn't be an issue. When it was working with DHCP, did you run an ifconfig to check the interface name or did you assume it was enp0s25? Also do you have an auto enp0s25 at the top of your config file? If you don't its possible that the interface is just not coming up on boot.

    – Andrew
    May 2 '16 at 0:30











  • Please edit your question and post the exact content of your /etc/network/interfaces file. While editing your message, highlight the text of this file, then click on the {} code link on the top of the message editor so that it will properly format the text making it easier for us to read the content. Also do execute this command ip address and perform the same steps to {} (code format) that output.

    – L. D. James
    May 2 '16 at 4:05

















the only thing I notice and it may have just been a typo here but I would change the Dns-nameservers to dns-nameservers probably not going to do anything to solve this issue but may stop other issues from happening

– John Orion
May 2 '16 at 0:20





the only thing I notice and it may have just been a typo here but I would change the Dns-nameservers to dns-nameservers probably not going to do anything to solve this issue but may stop other issues from happening

– John Orion
May 2 '16 at 0:20













Dns-nameservers is acceptable syntax wise so it shouldn't be an issue. When it was working with DHCP, did you run an ifconfig to check the interface name or did you assume it was enp0s25? Also do you have an auto enp0s25 at the top of your config file? If you don't its possible that the interface is just not coming up on boot.

– Andrew
May 2 '16 at 0:30





Dns-nameservers is acceptable syntax wise so it shouldn't be an issue. When it was working with DHCP, did you run an ifconfig to check the interface name or did you assume it was enp0s25? Also do you have an auto enp0s25 at the top of your config file? If you don't its possible that the interface is just not coming up on boot.

– Andrew
May 2 '16 at 0:30













Please edit your question and post the exact content of your /etc/network/interfaces file. While editing your message, highlight the text of this file, then click on the {} code link on the top of the message editor so that it will properly format the text making it easier for us to read the content. Also do execute this command ip address and perform the same steps to {} (code format) that output.

– L. D. James
May 2 '16 at 4:05





Please edit your question and post the exact content of your /etc/network/interfaces file. While editing your message, highlight the text of this file, then click on the {} code link on the top of the message editor so that it will properly format the text making it easier for us to read the content. Also do execute this command ip address and perform the same steps to {} (code format) that output.

– L. D. James
May 2 '16 at 4:05










7 Answers
7






active

oldest

votes


















77














I had the same problem and this was my solution:



sudo nano /etc/network/interfaces


and 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.8


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



enter image description here



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





share|improve this answer





















  • 2





    Great thanks I appreciate it. It seems to work now, with no problems. It is very solid right now!

    – TeeStar
    May 7 '16 at 2:07











  • In addition to the dns-nameservers fix, I had to use this fix: askubuntu.com/questions/574569/… My ISP is monkeybrains.net.

    – BSalita
    Aug 22 '16 at 23:38



















53














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


Then verify it is correct:



ip add





share|improve this answer



















  • 2





    The flush was necessary to avoid the old address being present on the interface (based on ip addr). The systemctl restart works too, though ifdown and ifup on the interface will work more selectively.

    – RichVel
    Nov 28 '16 at 13:28






  • 2





    thx @Grant. adding flush made this work

    – nysander
    Feb 1 '17 at 13:19






  • 2





    In Ubuntu 16.04 and newer flush is necessary!

    – Diego Duarte
    May 2 '17 at 12:05



















5














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


sudo ifdown eth0 && sudo ifup eth0






share|improve this answer





















  • 9





    Hi @lanni654321, maybe you should edit your answer and add a few word, briefly explaining what you are doing and why? i think that would make your answer even more helpful, what do you think?

    – Tshilidzi Mudau
    Oct 14 '16 at 6:58



















5














# 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





share|improve this answer





















  • 1





    ifcace should be iface on line 5

    – twoleggedhorse
    Jun 28 '17 at 14:33











  • @twoleggedhorse: Fixed the typo for the answer but I had to add a few # in the first line because you cannot have an edit without at least 6 changed characters that are not whitespace

    – Andrei Rinea
    Nov 28 '17 at 17:11



















3














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 ens160


And, create an empty file with the name of the network interface in:



~$ touch /etc/network/interfaces.d/ens160


It works...






share|improve this answer































    2














    I had the same problem and this was my solution:
    Remove all empty lines at the end of the file /etc/network/interface.






    share|improve this answer

































      0














      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.






      share|improve this answer























        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "89"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f766131%2fset-static-ip-ubuntu%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        7 Answers
        7






        active

        oldest

        votes








        7 Answers
        7






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        77














        I had the same problem and this was my solution:



        sudo nano /etc/network/interfaces


        and 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.8


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



        enter image description here



        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





        share|improve this answer





















        • 2





          Great thanks I appreciate it. It seems to work now, with no problems. It is very solid right now!

          – TeeStar
          May 7 '16 at 2:07











        • In addition to the dns-nameservers fix, I had to use this fix: askubuntu.com/questions/574569/… My ISP is monkeybrains.net.

          – BSalita
          Aug 22 '16 at 23:38
















        77














        I had the same problem and this was my solution:



        sudo nano /etc/network/interfaces


        and 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.8


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



        enter image description here



        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





        share|improve this answer





















        • 2





          Great thanks I appreciate it. It seems to work now, with no problems. It is very solid right now!

          – TeeStar
          May 7 '16 at 2:07











        • In addition to the dns-nameservers fix, I had to use this fix: askubuntu.com/questions/574569/… My ISP is monkeybrains.net.

          – BSalita
          Aug 22 '16 at 23:38














        77












        77








        77







        I had the same problem and this was my solution:



        sudo nano /etc/network/interfaces


        and 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.8


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



        enter image description here



        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





        share|improve this answer















        I had the same problem and this was my solution:



        sudo nano /etc/network/interfaces


        and 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.8


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



        enter image description here



        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






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 19 at 23:32

























        answered May 4 '16 at 20:20









        lewis4ulewis4u

        2,42331530




        2,42331530








        • 2





          Great thanks I appreciate it. It seems to work now, with no problems. It is very solid right now!

          – TeeStar
          May 7 '16 at 2:07











        • In addition to the dns-nameservers fix, I had to use this fix: askubuntu.com/questions/574569/… My ISP is monkeybrains.net.

          – BSalita
          Aug 22 '16 at 23:38














        • 2





          Great thanks I appreciate it. It seems to work now, with no problems. It is very solid right now!

          – TeeStar
          May 7 '16 at 2:07











        • In addition to the dns-nameservers fix, I had to use this fix: askubuntu.com/questions/574569/… My ISP is monkeybrains.net.

          – BSalita
          Aug 22 '16 at 23:38








        2




        2





        Great thanks I appreciate it. It seems to work now, with no problems. It is very solid right now!

        – TeeStar
        May 7 '16 at 2:07





        Great thanks I appreciate it. It seems to work now, with no problems. It is very solid right now!

        – TeeStar
        May 7 '16 at 2:07













        In addition to the dns-nameservers fix, I had to use this fix: askubuntu.com/questions/574569/… My ISP is monkeybrains.net.

        – BSalita
        Aug 22 '16 at 23:38





        In addition to the dns-nameservers fix, I had to use this fix: askubuntu.com/questions/574569/… My ISP is monkeybrains.net.

        – BSalita
        Aug 22 '16 at 23:38













        53














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


        Then verify it is correct:



        ip add





        share|improve this answer



















        • 2





          The flush was necessary to avoid the old address being present on the interface (based on ip addr). The systemctl restart works too, though ifdown and ifup on the interface will work more selectively.

          – RichVel
          Nov 28 '16 at 13:28






        • 2





          thx @Grant. adding flush made this work

          – nysander
          Feb 1 '17 at 13:19






        • 2





          In Ubuntu 16.04 and newer flush is necessary!

          – Diego Duarte
          May 2 '17 at 12:05
















        53














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


        Then verify it is correct:



        ip add





        share|improve this answer



















        • 2





          The flush was necessary to avoid the old address being present on the interface (based on ip addr). The systemctl restart works too, though ifdown and ifup on the interface will work more selectively.

          – RichVel
          Nov 28 '16 at 13:28






        • 2





          thx @Grant. adding flush made this work

          – nysander
          Feb 1 '17 at 13:19






        • 2





          In Ubuntu 16.04 and newer flush is necessary!

          – Diego Duarte
          May 2 '17 at 12:05














        53












        53








        53







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


        Then verify it is correct:



        ip add





        share|improve this answer













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


        Then verify it is correct:



        ip add






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '16 at 9:50









        GrantGrant

        63057




        63057








        • 2





          The flush was necessary to avoid the old address being present on the interface (based on ip addr). The systemctl restart works too, though ifdown and ifup on the interface will work more selectively.

          – RichVel
          Nov 28 '16 at 13:28






        • 2





          thx @Grant. adding flush made this work

          – nysander
          Feb 1 '17 at 13:19






        • 2





          In Ubuntu 16.04 and newer flush is necessary!

          – Diego Duarte
          May 2 '17 at 12:05














        • 2





          The flush was necessary to avoid the old address being present on the interface (based on ip addr). The systemctl restart works too, though ifdown and ifup on the interface will work more selectively.

          – RichVel
          Nov 28 '16 at 13:28






        • 2





          thx @Grant. adding flush made this work

          – nysander
          Feb 1 '17 at 13:19






        • 2





          In Ubuntu 16.04 and newer flush is necessary!

          – Diego Duarte
          May 2 '17 at 12:05








        2




        2





        The flush was necessary to avoid the old address being present on the interface (based on ip addr). The systemctl restart works too, though ifdown and ifup on the interface will work more selectively.

        – RichVel
        Nov 28 '16 at 13:28





        The flush was necessary to avoid the old address being present on the interface (based on ip addr). The systemctl restart works too, though ifdown and ifup on the interface will work more selectively.

        – RichVel
        Nov 28 '16 at 13:28




        2




        2





        thx @Grant. adding flush made this work

        – nysander
        Feb 1 '17 at 13:19





        thx @Grant. adding flush made this work

        – nysander
        Feb 1 '17 at 13:19




        2




        2





        In Ubuntu 16.04 and newer flush is necessary!

        – Diego Duarte
        May 2 '17 at 12:05





        In Ubuntu 16.04 and newer flush is necessary!

        – Diego Duarte
        May 2 '17 at 12:05











        5














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


        sudo ifdown eth0 && sudo ifup eth0






        share|improve this answer





















        • 9





          Hi @lanni654321, maybe you should edit your answer and add a few word, briefly explaining what you are doing and why? i think that would make your answer even more helpful, what do you think?

          – Tshilidzi Mudau
          Oct 14 '16 at 6:58
















        5














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


        sudo ifdown eth0 && sudo ifup eth0






        share|improve this answer





















        • 9





          Hi @lanni654321, maybe you should edit your answer and add a few word, briefly explaining what you are doing and why? i think that would make your answer even more helpful, what do you think?

          – Tshilidzi Mudau
          Oct 14 '16 at 6:58














        5












        5








        5







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


        sudo ifdown eth0 && sudo ifup eth0






        share|improve this answer















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


        sudo ifdown eth0 && sudo ifup eth0







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Oct 14 '16 at 23:18









        Kevin Bowen

        14.7k155970




        14.7k155970










        answered Oct 14 '16 at 1:41









        lanni654321lanni654321

        15111




        15111








        • 9





          Hi @lanni654321, maybe you should edit your answer and add a few word, briefly explaining what you are doing and why? i think that would make your answer even more helpful, what do you think?

          – Tshilidzi Mudau
          Oct 14 '16 at 6:58














        • 9





          Hi @lanni654321, maybe you should edit your answer and add a few word, briefly explaining what you are doing and why? i think that would make your answer even more helpful, what do you think?

          – Tshilidzi Mudau
          Oct 14 '16 at 6:58








        9




        9





        Hi @lanni654321, maybe you should edit your answer and add a few word, briefly explaining what you are doing and why? i think that would make your answer even more helpful, what do you think?

        – Tshilidzi Mudau
        Oct 14 '16 at 6:58





        Hi @lanni654321, maybe you should edit your answer and add a few word, briefly explaining what you are doing and why? i think that would make your answer even more helpful, what do you think?

        – Tshilidzi Mudau
        Oct 14 '16 at 6:58











        5














        # 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





        share|improve this answer





















        • 1





          ifcace should be iface on line 5

          – twoleggedhorse
          Jun 28 '17 at 14:33











        • @twoleggedhorse: Fixed the typo for the answer but I had to add a few # in the first line because you cannot have an edit without at least 6 changed characters that are not whitespace

          – Andrei Rinea
          Nov 28 '17 at 17:11
















        5














        # 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





        share|improve this answer





















        • 1





          ifcace should be iface on line 5

          – twoleggedhorse
          Jun 28 '17 at 14:33











        • @twoleggedhorse: Fixed the typo for the answer but I had to add a few # in the first line because you cannot have an edit without at least 6 changed characters that are not whitespace

          – Andrei Rinea
          Nov 28 '17 at 17:11














        5












        5








        5







        # 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





        share|improve this answer















        # 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






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 28 '17 at 17:32









        David Foerster

        28.5k1367113




        28.5k1367113










        answered May 12 '16 at 9:34









        rajanrajan

        511




        511








        • 1





          ifcace should be iface on line 5

          – twoleggedhorse
          Jun 28 '17 at 14:33











        • @twoleggedhorse: Fixed the typo for the answer but I had to add a few # in the first line because you cannot have an edit without at least 6 changed characters that are not whitespace

          – Andrei Rinea
          Nov 28 '17 at 17:11














        • 1





          ifcace should be iface on line 5

          – twoleggedhorse
          Jun 28 '17 at 14:33











        • @twoleggedhorse: Fixed the typo for the answer but I had to add a few # in the first line because you cannot have an edit without at least 6 changed characters that are not whitespace

          – Andrei Rinea
          Nov 28 '17 at 17:11








        1




        1





        ifcace should be iface on line 5

        – twoleggedhorse
        Jun 28 '17 at 14:33





        ifcace should be iface on line 5

        – twoleggedhorse
        Jun 28 '17 at 14:33













        @twoleggedhorse: Fixed the typo for the answer but I had to add a few # in the first line because you cannot have an edit without at least 6 changed characters that are not whitespace

        – Andrei Rinea
        Nov 28 '17 at 17:11





        @twoleggedhorse: Fixed the typo for the answer but I had to add a few # in the first line because you cannot have an edit without at least 6 changed characters that are not whitespace

        – Andrei Rinea
        Nov 28 '17 at 17:11











        3














        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 ens160


        And, create an empty file with the name of the network interface in:



        ~$ touch /etc/network/interfaces.d/ens160


        It works...






        share|improve this answer




























          3














          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 ens160


          And, create an empty file with the name of the network interface in:



          ~$ touch /etc/network/interfaces.d/ens160


          It works...






          share|improve this answer


























            3












            3








            3







            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 ens160


            And, create an empty file with the name of the network interface in:



            ~$ touch /etc/network/interfaces.d/ens160


            It works...






            share|improve this answer













            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 ens160


            And, create an empty file with the name of the network interface in:



            ~$ touch /etc/network/interfaces.d/ens160


            It works...







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jul 18 '16 at 8:03









            ManuManu

            311




            311























                2














                I had the same problem and this was my solution:
                Remove all empty lines at the end of the file /etc/network/interface.






                share|improve this answer






























                  2














                  I had the same problem and this was my solution:
                  Remove all empty lines at the end of the file /etc/network/interface.






                  share|improve this answer




























                    2












                    2








                    2







                    I had the same problem and this was my solution:
                    Remove all empty lines at the end of the file /etc/network/interface.






                    share|improve this answer















                    I had the same problem and this was my solution:
                    Remove all empty lines at the end of the file /etc/network/interface.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Oct 24 '17 at 10:42









                    Videonauth

                    24.7k1272101




                    24.7k1272101










                    answered Oct 24 '17 at 10:26









                    AkYuAkYu

                    211




                    211























                        0














                        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.






                        share|improve this answer




























                          0














                          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.






                          share|improve this answer


























                            0












                            0








                            0







                            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.






                            share|improve this answer













                            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.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Feb 19 at 23:41









                            OleOle

                            7272820




                            7272820






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Ask Ubuntu!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f766131%2fset-static-ip-ubuntu%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                                is 'sed' thread safe

                                How to make a Squid Proxy server?