How can I change the IP and gateway addresses permanently?

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?

Asked By: aliatlii


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

Answered By: cremefraiche

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

‘ONBOOT’ = yes
‘BOOTPROTO’= ‘static’

5. done

Answered By: ojasvi singhal
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.