[GH-ISSUE #33] Bug: Adding a host can add duplicates with differing IPs #10

Closed
opened 2026-03-02 05:08:06 +03:00 by kerem · 0 comments
Owner

Originally created by @tomjn on GitHub (Jan 11, 2022).
Original GitHub issue: https://github.com/goodhosts/hostsfile/issues/33

This situation is not handled:

when adding hostname with IP
  if ( h.HasHostname( 'example.com' ) AND ! h.Has( ip,'example.com ) ) {
    remove hostname with old IP

If I add a hostname example.com with 1.1.1.1, then try to add the same hostname with 2.2.2.2 the result is that I now have 2 entries for example.com for both IPs. I expected a single entry for 2.2.2.2.

When adding a host, old entries should be removed.

This has recently caught us out over at VVV with the vagrant plugin usage when a VirtualBox restriction forced us to change the IP we use. Users who upgraded without halting their VMs kept the hosts file entry, and when they reprovisioned a second entry was added with the new IP. As a result requests to our domains were sent to the old IP, and destroying/halting the VM only triggered the new entry to be removed, the old entry being preserved and persisting the issue.

Originally created by @tomjn on GitHub (Jan 11, 2022). Original GitHub issue: https://github.com/goodhosts/hostsfile/issues/33 This situation is not handled: ``` when adding hostname with IP if ( h.HasHostname( 'example.com' ) AND ! h.Has( ip,'example.com ) ) { remove hostname with old IP ``` If I add a hostname `example.com` with `1.1.1.1`, then try to add the same hostname with `2.2.2.2` the result is that I now have 2 entries for `example.com` for both IPs. I expected a single entry for `2.2.2.2`. When adding a host, old entries should be removed. This has recently caught us out over at VVV with the vagrant plugin usage when a VirtualBox restriction forced us to change the IP we use. Users who upgraded without halting their VMs kept the hosts file entry, and when they reprovisioned a second entry was added with the new IP. As a result requests to our domains were sent to the old IP, and destroying/halting the VM only triggered the new entry to be removed, the old entry being preserved and persisting the issue.
kerem closed this issue 2026-03-02 05:08:06 +03:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hostsfile#10
No description provided.