We help IT Professionals succeed at work.

Can't asign static IP = /etc/network/interfaces:1: misplaced option

16,242 Views
Last Modified: 2011-10-19
Im new at VM, and extremly new at Linux. i know enough to get myself in trouble

i have a VM image of a linux system that was setup as DHCP, however our network does not use DHCP and i need to set it up as a static IP

ive done a bit of research and manged to vi /etc/network/interfaces and found how to add the information i need.

however when i
/etc/init.d/networking stop
/etc/init.d/networking start

i get the following error

error message
 * Configuring network interfaces...
/etc/network/interfaces:1: misplaced option
ifup: couldn't each interface file "/etc/network/interfaces"
[fail]

any help would be greatly appreciated
-=-=-= OLD FILE =-=-=-
# The loopback network interface
auto lo
iface lo inet loopback
 
# The primary network interface
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
 
-=-=-= NEW FILE =-=-=-
# The loopback network interface
auto lo
iface lo inet loopback
 
# The primary network interface
iface eth0 inet static
address 192.168.2.35
network 192.168.2.0
netmask 255.255.255.0
gateway 192.168.2.1

Open in new window

Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Sorry, that should be typo
Your /etc/network/interfaces should look like this:



# The loopback network interface
auto lo
iface lo inet loopback
 
# The primary network interface
auto eth0
iface eth0 inet static
        192.168.2.35
        network 192.168.2.0
        netmask 255.255.255.0        
        broadcast 192.168.2.255
        gateway 192.168.2.1

Open in new window

Commented:
(...once I'd stopped chuckling at the typo of "typo"... :) )

Can you check the permissions of /etc/network/interfaces?

Do this (in a terminal window):

  ls -l /etc/network/interfaces

If the first bit does not say -rw-r--r-- then type:

  sudo chmod 644 /etc/network/interfaces

If the 3rd and 4th parts do not both say "root", then type:

  sudo chown root:root /etc/network/interfaces

If that all looks okay, I'm not sure what it'll be, as the text you specified above looks fine.

Perhaps you could supply the output of this command:

  cat -e /etc/network/interfaces

The -e will reveal any strange escape/control codes in the file that might be confusing things.


Oh, and you'll probably want to add:

  auto eth0

above the

  iface eth0

line, else you will have to manually ifup eth0 after each reboot.

Commented:
Duh, yes, Roachy1979 has got it, you need to indent all the lines underneath the iface line, as they are options for that interface.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
whoops - well spotted MushyPea.....

:)

Author

Commented:
thanks for everyone's help, it was an issue with the remarks, i guess when i first hit s to edit the file, it deleted the #
error.jpg

Author

Commented:
thanks all
No problem - if you're new to linux and want to try a different command line text editor (or you don't need all the power of vi try nano)

:)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.