5

When you connect to a WiFi network, the router assigns an IP to the android device (like 192.168.1.105). Now when a FTP or HTTP file server is run on the android device, other devices should type that IP to connect to the server.

This IP is not fixed. When you switch to another WiFi network or enable hot-spot on android itself, it changes.

Is there any way to assign a fixed hostname (for example my-pixel) so other devices could use it instead of the IP (like ftp://my-pixel.local:4030)?

(I also asked this on Stack Overflow but no answer there)

5
  • 1
    Most phones send the name you have configured in About my phone -> Device Name to the DHCP server. The DHCP server in my Wifirouter uses this name and saves it as DNS name for the IP it had assigned to my phone. Just make sure your devices use the DNS server provided by your router and not a "privacy DNS server" from an external system (like Google DNS or Cloudflare DNS). Commented Jun 14, 2023 at 13:47
  • 1
    @Robert Thanks, but how does it work? There is a Phone Name that is like Brand Model XX10 (with spaces). Provided that it is connected to the local network how can I, for example, ping this from my computer? Commented Jun 14, 2023 at 14:11
  • 1
    Your computer has to ask your router for the dns name of the local device. If the router is configured to provide DNS services for local devices known by DHCP then it will lookup the phone name in it's DNS table. Note that spaces and underscore are not allowed in DNS, I don't know what happens if your phone tries to use an invalid DNS name. Open up the admin interface of your Wifi router and check what devices it lists and what names it has assigned to them. Commented Jun 14, 2023 at 14:34
  • How do I change the name of my Android device? Commented Jun 14, 2023 at 20:10
  • 1
    This question is similar to: How do I change the name of my Android device?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Mar 9 at 15:35

1 Answer 1

3

Starting with Android 11, the Network Stack module uses an overlayable boolean resource – config_dhcp_client_hostname – to determine whether the hostname should be sent to the DHCP server.

This property is false by default, but if your device is rooted, you can override it to make Android use Settings.Global.DEVICE_NAME as the hostname:

adb root adb shell cmd overlay fabricate --target-name NetworkStackConfig --target com.android.networkstack --name HostnameOverlay com.android.networkstack:bool/config_dhcp_client_hostname 0x12 0x01 adb shell cmd overlay enable com.android.shell:HostnameOverlay adb reboot 

Note that the target package name is either com.android.networkstack or com.android.networkstack.inprocess.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.