This file is indexed.

/usr/sbin/update-hostname-from-ip is in debian-edu-config 1.818+deb8u2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/sh -e
#
# Author: Petter Reinholdtsen <pere@hungry.com>
# Date:   2002-08-06
#
# Set current hostname to match the IP address on eth0.  This is
# useful when getting the IP address from DHCP.

LC_ALL=C
export LC_ALL
QUIET=echo
USEMAC=false
onlyprint=false

DNSDOMAIN=intern

log() {
    $QUIET "$2"
    logger -t update-hostname-from-ip "$1"
}

# Generate FQDN based on hardware MAC address
ether2hostname() {
    if [ "$1" ] ; then
	mac="$1"
    else
	mac=$(ifconfig $INTERFACE | awk '/Link encap:Ethernet  HWaddr/ { print $5; exit}')
    fi
    mac=$(echo $mac | sed 's/[^0-9a-f-]/-/gi')
    if [ "$mac" ] ; then
       fqdn="auto-mac-$mac.$DNSDOMAIN";
       echo $fqdn
    fi
}

# Map IP to FQDN
ip2hostname() {
    ip=$1
    host $ip | grep 'domain name pointer' | cut -d ' ' -f 5 | \
	rev |cut -d '.' -f 2-|rev
}

PATH="/sbin:$PATH"

INTERFACE="$(/sbin/route -n | awk '/^0\.0\.0\.0 / { print $8; exit }')"

if [ -z "$INTERFACE" ] ; then
    INTERFACE=eth0
fi

sethostname() {
    hostname="$1"
    namesource="$2"
    if hostname $hostname ; then
	echo $hostname > /etc/hostname
	log "info: changing hostname to $hostname based on $namesource"
    else
	log "error: unable to set hostname to $hostname."
	exit 1
    fi
}

# argument parsing
TEMP=$(getopt -n update-hostname-from-ip -o dmM:nI:q -- "$@")

# Abort when there was a bug
[ $? = 0 ] || die "error parsing arguments. Try $0 --help"       

eval set -- "$TEMP"
while true; do     
    case $1 in 
        -m)
            USEMAC=true; shift; continue
            ;;                                    
        -M)                            
            MAC="$2"; shift; shift; continue
            ;;
        -I)
            IP="$2"; shift; shift; continue
            ;;
        -q)
            QUIET=:; shift; continue
            ;;
        -n)
            onlyprint=true; shift; continue
            ;;
        --)
            # no more arguments to parse
            break
            ;;
        *)
            printf "Unknown option %s\n" "$1"
            exit 1
            ;;
    esac
done

# Extract current IP if non was provided on the command line
if [ -z "$IP" ] ; then
    IP=`ifconfig $INTERFACE 2>&1 |grep 'inet addr:'|tr a-zA-Z: " "|awk '{print $1; exit}'`
fi

if [ "127.0.0.1" = "$IP" ] ; then
    IP=""
fi

if [ "$IP" ] ; then
    HOSTNAME=$(ip2hostname $IP)
    SOURCE="reverse DNS of $IP"
elif $USEMAC ; then
    HOSTNAME=$(ether2hostname $MAC)
    SOURCE="hardware MAC address"
else
    exit 1
fi

if $USEMAC && [ -z "$HOSTNAME" ] ; then
    HOSTNAME=$(ether2hostname $MAC)
    SOURCE="hardware MAC address"
fi

# Already got the correct host name?
if [ "$HOSTNAME" = "$(uname -n)" ] ; then
    exit 0
fi

if [ "$HOSTNAME" ]; then
    if $onlyprint ; then
	echo $HOSTNAME
	exit 0
    else
	sethostname "$HOSTNAME" "$SOURCE"
    fi
else
    exit 1
fi

exit 0