简体   繁体   中英

Static and Dynamic Ip address problems

Let's say we are hosting on a Personal Computer and Server Program is written in Java.

1.If we host server using static IP-address then does that means we can change machine and replace it with other ones, restart machine as many times we want and our Client will still be able to communicate with us after system is back? 2.if we host server using Dynamic IP-address then just by restarting once the machine we have to tell every single client out there that new IP-address is this one? 3.Will Dynamic IP-addresses change even if we don't restart the machine ?

1: Yes, if the server has a static IP clients will always be able to count on the server being at that IP address.

2: Most likely, yes. In many networks the DHCP server will give the same IP back to a machine that has rebooted but you certainly should not count on that.

3: Yes - dynamically assigned IP addresses have a "TTL" - a time to live. This may be a long time (weeks or more) but they still could expire and change. Most often the machine will get the same IP back but, again, you should not count on that.

  1. Yes, a static ip address means that it is fixed. There is more to the whole system, of course, since there is resolution of an IP to a MAC address. Nonetheless, a static IP (assuming it is only on the network once) means that any machine with that IP will respond. So a client can always connect to the IP address.

Note: not a very friendly way to go.

  1. Just because something has a "dynamic" IP address does not necessarily mean it changes every single time. Using DHCP it is possible to assign the same IP address to the same MAC address each time. It is a much better approach than hardcoding an IP address to a machine.

    In addition, you really should not have your clients use an IP address to connect. They should look up the machine by a name in DNS. You can coordinate the DNS lookup to the DHCP, so machines do not need to do anything but resolve the hostname.

    However, as your question stands, if a machine uses DHCP and does not receive the same IP address each time, and you have your clients connecting by IP address, then on each new assignment the clients would need the new IP address.

  2. Whether a machine's IP address updates even when it does not restart is a policy that is controlled by the DHCP server. In general, there is a renewal time for an IP address. Without going into great deal, the client during the DHCP conversation may request the same IP address, but it is up to the server as to whether to hand out the same one or not. Conversely, most servers are configured to hand out the same IP address to a given MAC address as long as the DHCP cache is current. It is completely a policy decision.

At the end of the day, however, it seems like you are attempting to tie clients to a server's IP address, and this is not a good strategy. It is a better strategy to use DNS and have the clients resolve a hostname. If I am incorrectly inferring your intent, I apologize.

NOTE: I have used DHCP as the way to give out dynamic IP addresses. You might use some other strategy, but I think the concept is the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM