1

I'd like to assign a static IP address to my laptop when it connects to the mobile hotspot created by my Android 14 Xiaomi phone. This would allow me to access SFTP servers running on my laptop from my phone more easily. Additionally, it would be beneficial to have a static IP or a '.local' address for the phone itself, though setting a static IP for the laptop is my primary concern.

My laptop already has a .local address, but the address doesn't resolve in Android. (I thought this problem was solved in recent Android versions, but it still doesn't work.)

I can root the phone if needed.

1
  • 1
    The Android hotspot should always assign your laptop an IP address from the same IPv4 subnet. As long as you don't have other devices in the hotspot network that could potentially use the same IPv4 address you can simply pick an address from that subnet and assign it statically to your laptop.
    – Robert
    Commented Oct 3 at 11:00

1 Answer 1

1

Update: This does not work, as Android even randomizes the third part of the router IP, and uses a mask of 255.255.255.0.


I used Hammerspoon to detect when I am connecting to the Wi-Fi of my phone, and then run this Zsh script to set the static IP automatically:

function ip-router {
    netstat -nr | perl -ne 'if (/^default\s+(\d+\.\d+\.\d+\.\d+)/) { print "$1\n"; exit }' | head -n1
}

local router_ip
router_ip="$(ip-router)"
if [[ "${router_ip}" =~ '^192\.168\.187\.' ]] ; then
    networksetup -setmanual Wi-Fi 192.168.187.7 255.255.0.0 "${router_ip}"

else
    echo "$0: router_ip does not match expected subnet."
fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .