I recently installed Linux Ubuntu 14.04 to my computer. To enable internet connection I needed to change my IP and Gateway address. I did the following as a root user

# ifconfig eth0 "my ip address here" netmask up
# route add default gw " gw address here"

It works fine for a couple of minutes but then goes back to the previous settings every time. So, How can I change the IP and the gw addresses permanently?

  • Are you using network-manager? You probably are if you haven't installed another connection manager. – jpkotta May 21 '15 at 22:04
  • I am not using anything similar to that since I couldnt connect to the Internet. Just from command line. – aliatlii May 21 '15 at 22:05
  • Yes, but if you are in the default GUI (Unity), network-manager will automatically be started. It looks like a pair of arrows, one up, one down, in the system tray. – jpkotta May 21 '15 at 22:07
  • If network-manager is running, it start a dhcp client (probably dhclient); that will attempt to autoconfigure the network, and that's probably why your settings get overwritten. – jpkotta May 21 '15 at 22:08
  • So should I disable network-manager ?? – aliatlii May 21 '15 at 22:33

As stated by jpkotta, network-manager is likely the culprit.

You can see its status by running ps -aux | grep network-manager | grep <username>. If you get a result, it is running, otherwise it isn't.

It will keep overwriting any changes you make with ifconfig as long as it is running.

Kill network-manager by running sudo service network-manager stop.
You can bring it back up any time with sudo service network-manager start.

Once it is disabled, use ifconfig to set your static, OR edit your /etc/network/interfaces file to include something like:

auto eth0
iface eth0 inet static

Finally, run ifup -a to bring up the interfaces you have in your /etc/network/interfaces file.

All of this can be avoided though, if you'd rather not mess around with killing network manager. Just click on its icon in the taskbar and click 'edit connections'.


Commands which you have to fire are:

  1. Check your NIC ifconfig
  2. Choose one and set it with ip which you want to give: ifconfig enp0s8
  3. go to cd /etc/sysconfig/network-scripts/
  4. edit NIC file:

    # vim ifcfg-enp0s8 ~ write ---------- 'IPADDR' = ~ 'NETMASK'= ~ 'ONBOOT' = yes ~ 'BOOTPROTO'= 'static'

  5. done

  • 1
    There is already a more valid, complete, and well formatted answer. – Julie Pelletier Jul 4 '16 at 18:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.