How to change your hostname (device name) in Android 6.0.1 with adb (root required)

First you enable developer mode by tapping on the build number a bunch under about this phone.

Then you enable USB debugging. Under developer options.

Finally you connect to your computer with USB cable.

Run these commands:

adb shell
su
getprop net.hostname
setprop net.hostname <new_hostname>