0

I'm using my Laptop on several networks. When I'm at home or at the office I occasionally want to connect with my phone to a server running on my laptop (say MPD, ssh, transmission).

The problem I'm facing at the office is that my IP address changes often. Hence I need to change the IP the apps on my phone use to connect to the servers and it's pretty tedious. I don't have permission to configure the router at the office so it'll give a static IP specifically to my machine, as I've done at home.

What's more frustrating, is that the office's router doesn't seem to support local network DNS - my machine's name is NUX and typing e.g ssh NUX on my phone while at the office fails.

I've often heard about a static IP address configured on the machine and not on the router but I never figured out how to do that. If I'd like to configure that wouldn't the router expect me to want a static IP? It doesn't make sense that a router configured for DHCP will go along with a machine demanding a static IP.

Besides setting a static IP with such a router, I'm considering writing a dirty hack to workaround the issue: Run a script on startup that will parse the output of nmap -sP 192.168.1.0/24 and send some kind of message to the phone indicating it's own IP address.

I'm using connman on NixOS but I'm willing to consider an alternative network manager for the sake of making this work.

8
  • Why not use one of the myriad Dynamic DNS providers? Your described need exactly matches their offerings. – roaima Feb 13 '20 at 20:41
  • This scenario can easily be fixed firstly you must decide your static IP and then once that's done, You must configure a DHCP pool, but within the pool you must exclude the static address from being used by the DHCP pool. Once this is done you can enable DHCP on your device and assign your device a static IP. Next time When you start your device it will have a static IP and any other devices will use the DHCP you configured earlier on – printf Feb 13 '20 at 21:35
  • How do you get an IP address in the office? Wifi? wall jack? – user1794469 Feb 13 '20 at 22:08
  • @roaima I could use a Dynamic DNS provider but how would that help for a device that's already under the same network? It might have been possible to do so and configure the router to forward traffic from outside to a specific host, but as I said I don't have permission to configure that. – Doron Behar Feb 14 '20 at 16:04
  • @Qasim that seems like a fairly complete solution. Do you mean to configure the DHCP on my machine or on the router? I don't have permission to set such things on the router. I'd like to see your solution in an answer and not a comment :). – Doron Behar Feb 14 '20 at 16:06
0

This scenario can easily be fixed firstly you must decide your static IP and then once that's done, You must configure a DHCP pool, but within the pool you must exclude the static address from being used by the DHCP pool. Once this is done you can enable DHCP on your first device and assign your device a static IP on your second device. Next time When you start your device it will have a static IP and any other devices will use the DHCP you configured earlier on.

In regards to your comment on weather you should do the dhcp on a pc or router, it's better to do it on a router but since you dont have permissions you can do it on a server. If you dont have a server you can turn one of your old PC's if you have one into a server, by doing this you can then assign a dhcp pool to the server, it's not possible to configure a dhcp pool on a client pc such as a laptop or normal everyday use PC.

-1

First you can set a static IP in a router with dhcp service cause a static IP has preference over DHCP If the IP is free. You shouldn't use an IP is in use cause it will make an IP conflict and It won't work.
Try to get one IP that should be free and in the end of the range of the dhcp.

Configure your adapter in terminal:
1º Identify your network interface -> ifconfig
2º Configure your network interface with the static config -> ifconfig "adapter" "IP" netmask "mask" up -> Example: sudo ifconfig eth0 192.168.1.13 netmask 255.255.255.0 up
3º Configure the gateway -> router add default gw "IP"
Example: sudo route add default gw 192.168.1.1

2
  • What do you mean by "Configure your network interface with the static config"? Are you absolutely sure I need no cooperation from my router to have a static IP? My main lack of understanding seems related exactly to this - How come a router configured to assign clients via DHCP would just give me a static IP? – Doron Behar Feb 14 '20 at 16:10
  • You don't need cooperation from your router but for the optimal configuration you should have access to the router and configure a reserve IP address. This is not the optimal configuration but It will work if you choose a free IP in the end of the range of the dhcp. I mean, dhcp is a IP request but if you tell the router I want this IP, the router will give you that IP unless the configuration of the router don't allow this. – user703702 Feb 14 '20 at 16:29
-1

It's an interesting challenge, which you could address from your phone instead? My idea would be to update /etc/hosts on your phone (if rooted) to point to the current IP of NUX. You'll still have to obtain the IP, but you would only need to apply it in one place of your phone and could use the hostname NUX in all your client apps. If your phone is not rooted you could achieve the same with Hosts Go (Disclaimer, just googled this via this post)

Another way could be to buy the cheapest USB WiFi adapter you can get and configure it as an AP (or bridged network adapter) with fixed IP on NUX, and access that one from your phone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.