Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have an issue where, each time I start my CentOS 5.6 VM, DHCP (I believe) is allocating my VM a different IP. I have the VM mapped as a Samba share in Windows 7 and this changes between 192.168.0.8, 192.168.0.9 and 192.168.0.10 each time meaning I have to mount a new drive in Windows each time.

This is also frustrating as I have to update my hosts file to point to a different IP each time and any projects I have pointing to the Samba share in my IDE are also gone.

Is there a way that I can set the IP to be the same each time in the Devernet Configuration under the setup tool in CentOS?

[root@dev ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 08:00:27:f2:9f:d6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.8/24 brd 192.168.0.255 scope global eth0

Here is a screenshot of the Devernet Configuration under the setup utility in CentOS. I had Use DHCP on, but I have turned it off in this screenshot.

enter image description here

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

There are two ways to resolve this issue: move to a static IP address and related configuration for the server completely outside of the DHCP server's domains (you'll have to configure the IP address, netmask, DNS server(s), etc., on the host in question), or tell the DHCP server to always assign the same IP address for this particular interface.

Most DHCP server implementations support assigning a host (actually a network interface) a specific IP address, which will be handed out whenever that NIC requests an IP address without increasing the risk of collisions (since it's still the DHCP server handling the assignment). This is the route I would suggest that you take.

However, exactly how to do that depends on which DHCP server you are using.

share|improve this answer
    
Thanks for the suggestion, am I correct in thinking I can set the specific IP address from within the setup > Devernet Config utility in CentOS? Does the IP have to be within a certain range? If so, how can I determine what that range is? –  crmpicco Feb 1 '13 at 14:39
1  
It depends on which approach you want to take. Static IP addresses are set on each host. Fixed, DHCP-assigned IP addresses are set in/on the DHCP server. If you give the host a fixed IP address through the DHCP server, you don't need to worry about which ranges are applicable. If you set a static IP address for one host but keep using DHCP elsewhere, that static IP address must be coordinated with the DHCP server to avoid collisions. Either way, the DHCP server is involved (unless you move to all static IPs). –  Michael Kjörling Feb 1 '13 at 14:54
    
A static IP is fine for me, Michael. I am having some trouble with the configuration though. As I say, DHCP on my router is rotating me between 192.168.0.8, 9 and 10...so can I set it to 192.168.0.54 (like in my screenshot) to safe collisions? What should my Default gateway IP be as there's limited documentation out there for this utility. –  crmpicco Feb 1 '13 at 15:21
1  
If you are happy with a static IP configured on the host, then you can simply copy the current settings. The /24 after the IP address in the ip a output means you are using a 24-bit netmask, so the netmask is 255.255.255.0. For the default route, try route -n | grep ^0.0.0.0; the IP address in the second field of the single line output is your default gateway. Whether this will be collision-safe is anyone's guess without -- again -- a look at the DHCP server settings. –  Michael Kjörling Feb 1 '13 at 15:25
    
Fanstastic! Thanks a lot. I've done a ifdown and ifup and mapped a new drive for 192.168.0.54 and it seems to be working fine. I'm just going to restart the VM and the machine itself to see if it connects OK after a restart and doesn't try and go through DHCP again. –  crmpicco Feb 1 '13 at 15:37
show 1 more comment

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.