Trying to reset local ip address with a script that edits /etc/network/interfaces

3

I'm trying to write a script that sets the local IP address. This is what I have so far:

#!/bin/sh
echo -n \
"# interfaces(5) file used by ifup(8) and ifdown(8)\n"\
"auto lo\n"\
"iface lo inet loopback\n"\
"auto eth0\n"\
"iface eth0 inet static\n"\
"  address 192.168.2.130\n"\
"  netmask 255.255.255.0\n"\
"  gateway 192.168.2.1\n"\
"  dns-nameservers 8.8.8.8\n"\
> /etc/network/interfaces
/sbin/ifup eth0

The file /etc/network/interfaces looks reasonably formatted, but the ifup command results in the following error:

RTNETLINK answers: File exists
Failed to bring up eth0.

How can I fix this?

jonderry

Posted 2014-06-05T18:03:38.007

Reputation: 837

Answers

6

I think this is caused by eth0 being already connected.

You might want to run /sbin/ifdown eth0 first.

YtvwlD

Posted 2014-06-05T18:03:38.007

Reputation: 101