0

I have a machine inside the university. The computers are connected to the internet, but have non-valid IPs (NAT).

When I am not at the university, I connect to the university's network via VPN, and then I can ssh to the machine using its LAN IP.

I have to remember the machine's IP before leaving the office, so that I can ssh to it. However, in case that the computer restarts due to a poweroff, the DHCP assigns a new IP to the machine, and I don't know the new IP.

How can I configure the linux (ubuntu) machine so that it sends me the IP?

Obviousely, no user has logged on when the machine restarts, so my question is in two parts:

  1. Where should I put the script so that it runs without login?
  2. What should the script do? I prefer that it sends me an email containing the new IP, but it does not work: When I try ifconfig | mail -s "new IP" [email protected], I receive no email.

1 Answer 1

2

I assume the email isn't working as there's no SMTP relay the PC can access. If it can get out to the Internet, you could use a cloud service to achieve the same thing. For example, I use rclone to upload a text file to Dropbox containing my latest DHCP address.

The place to put the script would be in a crontab file (either a user owned one or in /etc/cron.d) with the special schedule @reboot which executes the script on system startup. Like this:

@reboot /root/scripts/getcurrentip
3
  • Thanks. Are there any relays that I can use without providing my real email credentials? e.g. sending the email from localuser@localdomain to [email protected] using the mail command. I tried smtp.gmail.com and it does not work. I don't know so much about relays though :(
    – Ali
    Jul 12, 2017 at 14:12
  • @Ali, that's all out of my wheel house too. I would guess outgoing SMTP might be blocked (on port 25 at least). Try a different port. Gmail also allows incoming SMTP on port 465.
    – Darren
    Jul 12, 2017 at 14:14
  • 1
    You can probably directly deliver mail to your university's mail server without credentials. Generally, open relays are discouraged because they are useful to spammers for hiding the originating source of the message. However, you can usually connect directly to the target mail server and deliver your message. You could set your message sender to something like root@currentip to try to avoid message filters.
    – lungj
    Jul 12, 2017 at 15:05

You must log in to answer this question.

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