Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am connected to Internet through an ADSL modem, my ISP gives me an IP address, does Ubuntu log this IP address somewhere?

How can I configure Ubuntu to log the IP address?

share|improve this question
That depends on whether it's a pure modem or a modem-router (which many “ADSL modems” are, especially if they offer wifi). If it's a modem-router, your PC wouldn't have the information unless it tried actively to discover it, and wouldn't be notified if the address changed. What modem model do you have? If you run the command ifconfig, is the address that it shows (other than for lo) in one of the private ranges 10.*.*.*, 172.16-31.*.* and 192.168.*.*? – Gilles Aug 25 '13 at 11:25
I think I have a modem-router because ifconfig gives me – Alessandro Jacopson Aug 25 '13 at 11:36
Perhaps the question should be can Ubuntu query the modem or router for the IP address given by his ISP and log that? – Nil Aug 26 '13 at 0:31
up vote 2 down vote accepted

Or you can do it yourself, using curl to access a number of online services that respond with your public IP address.

Some of the services:


curl will output to terminal

curl > my_public_ip.txt will create or overide a txt file named my_public_ip.txt with the IP.

curl >> my_public_ip.txt will append the public IP every time the command runs.

You could create a small script to run the check and even add it as cron job to run say every time the machine reboots or at some intervals.

The simplest version could be:

#!/usr/bin/env bash

curl >> my_public_ip.txt
share|improve this answer

Logging the address of your PC

If your modem is purely a modem and your PC connects to your ISP directly, then the IP address that it obtains will be written to the system logs in /var/log/syslog. If you want this information to be easier to extract, you can log to a separate file.

If your ISP provides a PPP connection, then the scripts in /etc/ppp/ip-up.d are executed each time you connect (or /etc/ppp/ipv6-up.d if you have IPv6 connectivity). Add a script called /etc/ppp/ip-up.d/zzz_log_ip_address:

echo "$PPP_LOCAL $(TZ=UTC date '+%Y-%m-%d %H-%M-%S')" >>/var/log/ip-addresses

If your ISP provides an Ethernet connection, then the scripts in /etc/network/if-up.d are executed each time you connect. Add a script called /etc/network/if-up.d/zzz_log_ip_address:

if [ "$IFACE" = "lo" ]; then exit; fi # skip loopback interface
address=$(ip addr show eth1 | awk '$1 == "inet" {sub("/.*", "", $2); print $2}')
echo "$address $(TZ=UTC date '+%Y-%m-%d %H-%M-%S')" >>/var/log/ip-addresses

Obtaining your Internet address

The address of your PC on the local network may not be the address that you reach the Internet with, due to NAT. NAT allows many machines on a network to make outgoing connections from a single IP address. Many ADSL modems are in fact routers and NAT appliances in addition to being a modem. If your modem offers wifi, it's almost certainly a NAT appliance. If your modem allows multiple computers to connect (without one of the computers being set up for connection sharing), it is a NAT appliance.

If your PC is behind a NAT, then the only way it can know what its Internet address is is to ask a remote machine. There are many publicly-available websites that provide this information. You can retrieve this information at any given time, but you will not know when it changes. Most ISPs will change your IP address from time to time because this facilitates load balancing in their equipment. This typically happens once a day or once every few days.

If you want to log your IP address at regular intervals, you can make a cron job. Note that if your address changes multiple times between runs of the job, you have no way to know. In your crontab:

0 * * * * $HOME/bin/log-ip-address

The script ~/bin/log-ip-address:

address=$(wget -q -O -
previous=$(awk 'END {print $1}' <"$log_file") 2>/dev/null
if [ "$address" != "$previous" ]; then
  echo "$address $(TZ=UTC date '+%Y-%m-%d %H-%M-%S')" >>"$log_file"

Depending on your router model, it may be logging the IP addresses that it obtains, and there may be a way to make it send this information to your PC. This is very dependent on the router model, I can't give any general advice.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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