IP-Tag: Incorrect work with VMs #1692

Closed
opened 2025-11-20 05:14:55 -05:00 by saavagebueno · 19 comments
Owner

Originally created by @cjmaxik on GitHub (Aug 13, 2025).

Have you read and understood the above guidelines?

yes

📜 What is the name of the script you are using?

IP-Tag

📂 What was the exact command used to execute the script?

bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/tools/pve/add-iptag.sh)"

⚙️ What settings are you using?

  • Default Settings
  • Advanced Settings

🖥️ Which Linux distribution are you using?

Debian 12

📝 Provide a clear and concise description of the issue.

IT-Tag tags do not show for VMs with [Update_XXX] sections in their /etc/pve/qemu-server/XXX.conf config file. The tag is getting added to the end of the file instead of the first section (which is being applied to the UI). I don't know the exact reason the [Update_XXX] section exists, but the first section has no such title.

🔄 Steps to reproduce the issue.

  1. Have a VM with [Update_XXX] section(s) in /etc/pve/qemu-server/XXX.conf.
  2. Run iptag-run

Paste the full error output (if available).

No error

🖼️ Additional context (optional).

The config file for examination: 104.txt

Originally created by @cjmaxik on GitHub (Aug 13, 2025). ### ✅ Have you read and understood the above guidelines? yes ### 📜 What is the name of the script you are using? IP-Tag ### 📂 What was the exact command used to execute the script? `bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/tools/pve/add-iptag.sh)"` ### ⚙️ What settings are you using? - [x] Default Settings - [ ] Advanced Settings ### 🖥️ Which Linux distribution are you using? Debian 12 ### 📝 Provide a clear and concise description of the issue. IT-Tag tags do not show for VMs with [Update_XXX] sections in their `/etc/pve/qemu-server/XXX.conf` config file. The tag is getting added to the end of the file instead of the first section (which is being applied to the UI). I don't know the exact reason the [Update_XXX] section exists, but the first section has no such title. ### 🔄 Steps to reproduce the issue. 1. Have a VM with [Update_XXX] section(s) in `/etc/pve/qemu-server/XXX.conf`. 2. Run `iptag-run` ### ❌ Paste the full error output (if available). No error ### 🖼️ Additional context (optional). The config file for examination: [104.txt](https://github.com/user-attachments/files/21750104/104.txt)
saavagebueno added the bug label 2025-11-20 05:14:55 -05:00
Author
Owner

@MickLesk commented on GitHub (Aug 13, 2025):

What?

Examples? What excactly is the issue ?

@MickLesk commented on GitHub (Aug 13, 2025): What? Examples? What excactly is the issue ?
Author
Owner

@cjmaxik commented on GitHub (Aug 13, 2025):

The tag does not appear in the UI. I've attached the config file in the issue itself.

@cjmaxik commented on GitHub (Aug 13, 2025): The tag does not appear in the UI. I've attached the config file in the issue itself.
Author
Owner

@MickLesk commented on GitHub (Aug 13, 2025):

@DesertGamer

Idk what he mean. Can you check it? I think its missconfigured

@MickLesk commented on GitHub (Aug 13, 2025): @DesertGamer Idk what he mean. Can you check it? I think its missconfigured
Author
Owner

@cjmaxik commented on GitHub (Aug 13, 2025):

Debug logs confirm that the IP check works and the tag is being applied to the VM, but the tag itself does not appear in the UI.

[DEBUG] vm 104 final formatted_ips: 0.238
[DEBUG] vm 104 old_tags: '0.238'
[DEBUG] vm 104 new_tags: '0.238'
[DEBUG] vm 104 tags_equal: true
= VM 104: IP tag [0.238] unchanged

Moreover, if I were to add the tags manually, all the tags from this VM disappear from the UI, including those that are not following the TAG_FORMAT. This is because the script moves them to the end of the file.
If I were to add tags manually in the correct section, they would appear in the UI.

@cjmaxik commented on GitHub (Aug 13, 2025): Debug logs confirm that the IP check works and the tag is being applied to the VM, but the tag itself does not appear in the UI. ``` [DEBUG] vm 104 final formatted_ips: 0.238 [DEBUG] vm 104 old_tags: '0.238' [DEBUG] vm 104 new_tags: '0.238' [DEBUG] vm 104 tags_equal: true = VM 104: IP tag [0.238] unchanged ``` Moreover, if I were to add the tags manually, all the tags from this VM disappear from the UI, including those that are not following the `TAG_FORMAT`. This is because the script moves them to the end of the file. If I were to add tags manually in the correct section, they would appear in the UI.
Author
Owner

@MickLesk commented on GitHub (Aug 13, 2025):

Allright. Thats more clear for me.

@MickLesk commented on GitHub (Aug 13, 2025): Allright. Thats more clear for me.
Author
Owner

@vsc55 commented on GitHub (Aug 15, 2025):

Hi,
I ran into this problem today.
The problem occurs when you have a VM with one or more snapshots.
The script collects the tag field data from all snapshots and only updates the tag field of the most recent snapshot, leaving the VM without a tag, and the most recent snapshot in the .conf file contains all the tags (even duplicate ones).

Example:

Original configuration:

...
tags: debian;ha;linux
...

[debian13]
...
tags: debian;ha;linux
...

[ldap]
...
tags: debian;ha;linux
...

After running:

...
...

[debian13]
...
...

[ldap]
...
tags: debian;ha;linux;debian;ha;linux;debian;ha;linux;192.168.1.1
...

A possible fix:

--- iptag.org   2025-08-15 12:01:44.534083206 +0200
+++ iptag       2025-08-15 13:20:16.882778606 +0200
@@ -142,8 +142,8 @@
 # Get VM IPs using multiple methods with performance optimizations
 get_vm_ips() {
     local vmid=$1 ips=""
-    local vm_config="/etc/pve/qemu-server/${vmid}.conf"
-    [[ ! -f "$vm_config" ]] && return
+    # ensure VM exists without relying on the conf file
+    qm config "$vmid" >/dev/null 2>&1 || return

     debug_log "vm $vmid: starting optimized IP detection"

@@ -173,7 +173,8 @@
     fi

     # Method 1: Quick ARP table lookup (fastest)
-    local mac_addresses=$(grep -E "^net[0-9]+:" "$vm_config" | grep -oE "([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}" | head -3)
+    local mac_addresses=$(qm config "${vmid}" 2>/dev/null | grep -E "^net[0-9]+:" | grep -oE "([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}" | head -3)
+
     debug_log "vm $vmid: found MACs: $mac_addresses"

     # Quick ARP check without forced refresh (most common case)
@@ -250,7 +251,7 @@
         local mac_lower=$(echo "$mac" | tr '[:upper:]' '[:lower:]')

         # Get bridge interfaces
-        local bridges=$(grep -E "^net[0-9]+:" "$vm_config" | grep -oE "bridge=\w+" | cut -d= -f2 | head -1)
+        local bridges=$(qm config "${vmid}" 2>/dev/null | grep -E "^net[0-9]+:" | grep -oE "bridge=\\w+" | cut -d= -f2 | head -1)
         for bridge in $bridges; do
             if [[ -n "$bridge" && -d "/sys/class/net/$bridge" ]]; then
                 # Get bridge IP range
@@ -316,7 +317,7 @@
         fi

         # Check VM config for any IP hints
-        local config_ip=$(grep -E "(ip=|gw=)" "$vm_config" 2>/dev/null | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' | head -1)
+        local config_ip=$(qm config \"${vmid}\" 2>/dev/null | grep -E '^ipconfig[0-9]+:' | grep -Eo 'ip=([0-9]{1,3}\\.){3}[0-9]{1,3}(/[0-9]{1,2})?' | head -1 | cut -d= -f2 | cut -d/ -f1)
         if [[ -n "$config_ip" && "$config_ip" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
             debug_log "vm $vmid: found IP hint $config_ip in VM config"
             ips+="$config_ip "
@@ -346,10 +347,7 @@
         done < <(pct config "$vmid" 2>/dev/null)
     else
         current_ips_full=$(get_vm_ips "${vmid}")
-        local vm_config="/etc/pve/qemu-server/${vmid}.conf"
-        if [[ -f "$vm_config" ]]; then
-            local current_tags_raw=$(grep "^tags:" "$vm_config" 2>/dev/null | cut -d: -f2 | sed 's/^[[:space:]]*//')
-        fi
+        local current_tags_raw=$(qm config "${vmid}" 2>/dev/null | awk -F: '/^tags:/ {sub(/^[ \t]+/, "", $2); print $2; exit}')
     fi

     local current_tags=() next_tags=() current_ip_tags=()
@@ -472,12 +470,10 @@
         if [[ "$type" == "lxc" ]]; then
             pct set "${vmid}" -tags "$(IFS=';'; echo "${next_tags[*]}")" &>/dev/null
         else
-            local vm_config="/etc/pve/qemu-server/${vmid}.conf"
-            if [[ -f "$vm_config" ]]; then
-                sed -i '/^tags:/d' "$vm_config"
-                if [[ ${#next_tags[@]} -gt 0 ]]; then
-                    echo "tags: $(IFS=';'; echo "${next_tags[*]}")" >> "$vm_config"
-                fi
+            if [[ ${#next_tags[@]} -gt 0 ]]; then
+                qm set "${vmid}" -tags "$(IFS=';'; echo "${next_tags[*]}")" >/dev/null
+            else
+                qm set "${vmid}" -delete tags >/dev/null
             fi
         fi
     else
@vsc55 commented on GitHub (Aug 15, 2025): Hi, I ran into this problem today. The problem occurs when you have a VM with one or more snapshots. The script collects the tag field data from all snapshots and only updates the tag field of the most recent snapshot, leaving the VM without a tag, and the most recent snapshot in the .conf file contains all the tags (even duplicate ones). **Example:** Original configuration: ``` ... tags: debian;ha;linux ... [debian13] ... tags: debian;ha;linux ... [ldap] ... tags: debian;ha;linux ... ``` After running: ``` ... ... [debian13] ... ... [ldap] ... tags: debian;ha;linux;debian;ha;linux;debian;ha;linux;192.168.1.1 ... ``` **A possible fix:** ```bash --- iptag.org 2025-08-15 12:01:44.534083206 +0200 +++ iptag 2025-08-15 13:20:16.882778606 +0200 @@ -142,8 +142,8 @@ # Get VM IPs using multiple methods with performance optimizations get_vm_ips() { local vmid=$1 ips="" - local vm_config="/etc/pve/qemu-server/${vmid}.conf" - [[ ! -f "$vm_config" ]] && return + # ensure VM exists without relying on the conf file + qm config "$vmid" >/dev/null 2>&1 || return debug_log "vm $vmid: starting optimized IP detection" @@ -173,7 +173,8 @@ fi # Method 1: Quick ARP table lookup (fastest) - local mac_addresses=$(grep -E "^net[0-9]+:" "$vm_config" | grep -oE "([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}" | head -3) + local mac_addresses=$(qm config "${vmid}" 2>/dev/null | grep -E "^net[0-9]+:" | grep -oE "([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}" | head -3) + debug_log "vm $vmid: found MACs: $mac_addresses" # Quick ARP check without forced refresh (most common case) @@ -250,7 +251,7 @@ local mac_lower=$(echo "$mac" | tr '[:upper:]' '[:lower:]') # Get bridge interfaces - local bridges=$(grep -E "^net[0-9]+:" "$vm_config" | grep -oE "bridge=\w+" | cut -d= -f2 | head -1) + local bridges=$(qm config "${vmid}" 2>/dev/null | grep -E "^net[0-9]+:" | grep -oE "bridge=\\w+" | cut -d= -f2 | head -1) for bridge in $bridges; do if [[ -n "$bridge" && -d "/sys/class/net/$bridge" ]]; then # Get bridge IP range @@ -316,7 +317,7 @@ fi # Check VM config for any IP hints - local config_ip=$(grep -E "(ip=|gw=)" "$vm_config" 2>/dev/null | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' | head -1) + local config_ip=$(qm config \"${vmid}\" 2>/dev/null | grep -E '^ipconfig[0-9]+:' | grep -Eo 'ip=([0-9]{1,3}\\.){3}[0-9]{1,3}(/[0-9]{1,2})?' | head -1 | cut -d= -f2 | cut -d/ -f1) if [[ -n "$config_ip" && "$config_ip" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then debug_log "vm $vmid: found IP hint $config_ip in VM config" ips+="$config_ip " @@ -346,10 +347,7 @@ done < <(pct config "$vmid" 2>/dev/null) else current_ips_full=$(get_vm_ips "${vmid}") - local vm_config="/etc/pve/qemu-server/${vmid}.conf" - if [[ -f "$vm_config" ]]; then - local current_tags_raw=$(grep "^tags:" "$vm_config" 2>/dev/null | cut -d: -f2 | sed 's/^[[:space:]]*//') - fi + local current_tags_raw=$(qm config "${vmid}" 2>/dev/null | awk -F: '/^tags:/ {sub(/^[ \t]+/, "", $2); print $2; exit}') fi local current_tags=() next_tags=() current_ip_tags=() @@ -472,12 +470,10 @@ if [[ "$type" == "lxc" ]]; then pct set "${vmid}" -tags "$(IFS=';'; echo "${next_tags[*]}")" &>/dev/null else - local vm_config="/etc/pve/qemu-server/${vmid}.conf" - if [[ -f "$vm_config" ]]; then - sed -i '/^tags:/d' "$vm_config" - if [[ ${#next_tags[@]} -gt 0 ]]; then - echo "tags: $(IFS=';'; echo "${next_tags[*]}")" >> "$vm_config" - fi + if [[ ${#next_tags[@]} -gt 0 ]]; then + qm set "${vmid}" -tags "$(IFS=';'; echo "${next_tags[*]}")" >/dev/null + else + qm set "${vmid}" -delete tags >/dev/null fi fi else ```
Author
Owner

@DesertGamer commented on GitHub (Aug 15, 2025):

I'm sorry for not joining your conversation right away, I was really busy. I have been preparing a big update to my script for several weeks now and I will definitely fix it in the next update.

@DesertGamer commented on GitHub (Aug 15, 2025): I'm sorry for not joining your conversation right away, I was really busy. I have been preparing a big update to my script for several weeks now and I will definitely fix it in the next update.
Author
Owner

@proddy commented on GitHub (Aug 23, 2025):

Probably unrelated, I recently updated to Proxmox 9.0.5 and the IP tags are not detected anymore. Running iptag-run shows for each of my LXCs "No IP detected, tags unchanged". Any ideas?

@proddy commented on GitHub (Aug 23, 2025): Probably unrelated, I recently updated to Proxmox 9.0.5 and the IP tags are not detected anymore. Running `iptag-run` shows for each of my LXCs "No IP detected, tags unchanged". Any ideas?
Author
Owner

@oharvey2090 commented on GitHub (Aug 28, 2025):

Probably unrelated, I recently updated to Proxmox 9.0.5 and the IP tags are not detected anymore. Running iptag-run shows for each of my LXCs "No IP detected, tags unchanged". Any ideas?

Same issue for me today

@oharvey2090 commented on GitHub (Aug 28, 2025): > Probably unrelated, I recently updated to Proxmox 9.0.5 and the IP tags are not detected anymore. Running `iptag-run` shows for each of my LXCs "No IP detected, tags unchanged". Any ideas? Same issue for me today
Author
Owner

@DesertGamer commented on GitHub (Sep 2, 2025):

The update is ready, today I will make a Pull Request and you can use this script again.

@DesertGamer commented on GitHub (Sep 2, 2025): The update is ready, today I will make a Pull Request and you can use this script again.
Author
Owner

@DesertGamer commented on GitHub (Sep 2, 2025):

After these changes are added to the repository, you will simply need to call this script and select the item to update. The config has not changed in any way, so just updating the main file is enough.

@DesertGamer commented on GitHub (Sep 2, 2025): After these changes are added to the repository, you will simply need to call this script and select the item to update. The config has not changed in any way, so just updating the main file is enough.
Author
Owner

@cjmaxik commented on GitHub (Sep 4, 2025):

It seems like the issue is not fixed with this new version. It still adds tags to the end of the file.

@cjmaxik commented on GitHub (Sep 4, 2025): It seems like the issue is not fixed with this new version. It still adds tags to the end of the file.
Author
Owner

@DesertGamer commented on GitHub (Sep 4, 2025):

@cjmaxik Are you sure you've updated the script? Since I wrote the tests, I use this script on my home server and everything works as it should.

@DesertGamer commented on GitHub (Sep 4, 2025): @cjmaxik Are you sure you've updated the script? Since I wrote the tests, I use this script on my home server and everything works as it should.
Author
Owner

@cjmaxik commented on GitHub (Sep 4, 2025):

I am pretty sure, yeah. I can see new ✓ and ✗ glyphs, so it must be the updated one.

@cjmaxik commented on GitHub (Sep 4, 2025): I am pretty sure, yeah. I can see new ✓ and ✗ glyphs, so it must be the updated one.
Author
Owner

@DesertGamer commented on GitHub (Sep 4, 2025):

You had to choose the script update option, did you do it? My local machine is working correctly

@DesertGamer commented on GitHub (Sep 4, 2025): You had to choose the script update option, did you do it? My local machine is working correctly
Author
Owner

@cjmaxik commented on GitHub (Sep 4, 2025):

Yes, I did.
UPD: Removed the tags manually and run iptag-run - tags are added at the end of the file, like before.
Removed /usr/local/bin/iptag-run manually, installed the script again - no changes.

@cjmaxik commented on GitHub (Sep 4, 2025): Yes, I did. UPD: Removed the tags manually and run `iptag-run` - tags are added at the end of the file, like before. Removed `/usr/local/bin/iptag-run` manually, installed the script again - no changes.
Author
Owner

@proddy commented on GitHub (Sep 4, 2025):

I just did the update (bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/tools/pve/add-iptag.sh)") and confirm it works now on Proxmox 9.0.6. I see IP addresses as before.

Thanks @DesertGamer !

@proddy commented on GitHub (Sep 4, 2025): I just did the update (`bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/tools/pve/add-iptag.sh)"`) and confirm it works now on Proxmox 9.0.6. I see IP addresses as before. Thanks @DesertGamer !
Author
Owner

@keonramses commented on GitHub (Sep 17, 2025):

Issue still persists if VM has a snapshot. Removing snapshot allows the vm to be tagged.

@keonramses commented on GitHub (Sep 17, 2025): Issue still persists if VM has a snapshot. Removing snapshot allows the vm to be tagged.
Author
Owner

@DesertGamer commented on GitHub (Sep 18, 2025):

@keonramses I'll test it today, if that's really the case, then I'll add a fix.

@DesertGamer commented on GitHub (Sep 18, 2025): @keonramses I'll test it today, if that's really the case, then I'll add a fix.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SVI/ProxmoxVE#1692