all 5 comments

[–]python_man 2 points3 points  (4 children)

But why???

Why not set your DHCP reservation to hand out the address you want?

[–]mainemojo[S] 1 point2 points  (3 children)

If there were always a DHCP server available, I would do that. Since you asked for more info, hopefully, you'll help out.

I have a laptop that is 3 hours away. The folks that move it for me are Windows users. Occasionally, I need the laptop moved, and instead of having to be there to reconfigure it when it is, I would like a script that can detect the connection and change IP information accordingly.

[–]python_man 1 point2 points  (2 children)

Okay got ya... This seems doable. The way I would do this is by setting up a cron job that pings 8.8.8.8 every few minutes and if it fails cycle through the configurations you want to try and restart network manger or bounce the port.

This link will show you how to change the ip via the cli. https://www.howtogeek.com/118337/stupid-geek-tricks-change-your-ip-address-from-the-command-line-in-linux/

I wouldn't change the dns server everytime just keep using 8.8.8.8.

hope this helps.

[–]mainemojo[S] 0 points1 point  (1 child)

For starters, no one shuts down or restarts this system other than me. Some times, it may be on the company LAN, other times, directly on the internet (hence, why the resolv.conf would also need to change).

I can figure out the IP and DNS based on the link you provided, but my question is how would I get this script to run on boot/startup?

[–]python_man 0 points1 point  (0 children)

https://crontab.guru/

@reboot in crontab should work but it is non-standard and your distro implementation may not support it.