Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I change the IP address of an interface from a script?

I should say that I don't want to use ifconfig and also I don't want to edit the /etc/network/interfaces file manually. I need a script.

share|improve this question

If you are using ifup to configure the interface then you can define multiple so-called logical interface definitions for the interface and switch among them using ifup and ifdown. For example, you can define "iface home" and "iface work" in /etc/network/interfaces and then bring up eth0 either with "ifup eth0=home" or "ifup eth0=eth0-work". See ifup(8). Example of doing this from a script follows.

ifdown eth0
ifup eth0=home

If you are using NetworkManager to configure the interface then you can define multiple so-called connections and switch between them using the nmcli command.

nmcli con down id  'Wired connection work'
nmcli con up id  'Wired connection home'

If you are using neither ifupdown nor NetworkManager and you don't want to use ifconfig then you can use the ip utility. See ip(8).

ip link set dev eth0 ...
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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