Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I don't know a priori if a DHCP server would be present in the environment. So, I would like to set a dynamic IP address if there is a DHCP server, instead, I would like to set a static IP address if there isn't any DHCP server. Automatically.

I have just one network interface, eth0.

I tried to edit the /etc/network/interfaces like that:

auto eth0 eth0:1

iface eth0 inet dhcp
iface eth0:1 inet static
address 192.168.1.150
netmask 255.255.255.0
gateway 192.168.1.10

but it did not work.

I also tried this way

auto eth0

iface eth0 inet static
address 192.168.1.150
netmask 255.255.255.0
gateway 192.168.1.10
iface eth0 inet dhcp

but I had no success. I also tried to use the default iface:

iface default inet static
address 192.168.1.150
netmask 255.255.255.0
gateway 192.168.1.10

Can you explain to me what is the default iface? when do you have to use it?

any idea about how to have a static or dynamic IP address with just one network interface?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Try this:

auto eth0  
iface eth0 inet dhcp

auto eth0:1  
iface eth0:1 inet static  
address 192.168.1.150  
netmask 255.255.255.0  
gateway 192.168.1.10
share|improve this answer
    
it doesn't work. It is the same thing I already tried –  Gappa Jun 10 '13 at 13:45
    
They should be on separate stanzas, but when you say they don't work, what doesn't work exactly? –  NickW Jun 10 '13 at 13:47
    
I'm testing if I could reach a computer, with a static ip address, from another computer, just connecting each other with a LAN without passing through a router. The 2 computers are in the same subnet. –  Gappa Jun 10 '13 at 13:54
    
and if apply that configuration I cannot reach the computer –  Gappa Jun 10 '13 at 13:55
    
From inside, what does the machine say? Is the network DHCP or static, and what does ip route show say? –  NickW Jun 10 '13 at 14:11

Your Answer

 
discard

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.