Previous Post | Top | Next Post |
TOC
Here is a memo over IP address and its logging.
Local IP address
Local IP address can be obtained by using ip addr
.
$ ip addr
For processing this output with script, use of -o
option is handy.
Global IP address
If a workstation is behind the firewall, Global IP address is that for the gateway device.
Googling “what is my IP” gives lots of sites offering Global IP verification.
Here are interesting articles on this topic.
- How to check IPv6 address via command line? – good starting point
- ifconfig.co — What is my IP address? – good for script processing
- what is my ip address – IPv4, IPv6 address
- what is my ip – IPv4, IPv6 address
- NordVPN – IPアドレスを変更するべき理由 – This sometimes gives better geo location than ISP address (IPv4 only)
As I checked my IP connection situation:
- Residential shared broadband service (Tsunagu net)
- 100BaseT connection to home
- 10BaseT home Wifi router to PC (wlpxxx)
- IPv4 only service
- Global IPv4: 113.xxx.xxx.xxx (Tokyo)
- (Local IPv4: 192.168.0.xxx) – Class C LAN address (RFC1918)
- Mobile network service (IIJ)
- G4 to iPhone
- USB ethernet connection to PC (enxba5dxxxxxxxx)
- Global IPv4: 163.49.xxx.xxx (Kyoto)
- (Local IPv4: 172.20.xxx.xxx) – Class B LAN address (RFC1918)
- Global IPv6: 2001:240:2412:fa46:209b:xxxx:xxxx:xxxx (Shizuoka)
- (Local IPv6: 2001:240:2412:fa46:209b:xxxx:xxxx:xxxx – match global IP)
So I don’t get global IP with IPv4 but have global IP with IPv6.
Logging IP address with systemd timer
~/.config/systemd/user/myip.service
[Unit]
Description=Check external IP address
Documentation=man:myip(1)
# journalctl -a -b -t myip
[Service]
Type=oneshot
Nice=15
# ifconfig.co can be other IP servicing similar functionality.
# See https://serverfault.com/questions/1007184/how-to-check-ipv6-address-via-command-line
ExecStart=systemd-cat -p 5 -t "myip" sh -c 'echo "External IP: IPv4=$(curl -4 https://ifconfig.co 2>/dev/null)"'
ExecStart=systemd-cat -p 5 -t "myip" sh -c 'echo "External IP: IPv6=$(curl -6 https://ifconfig.co 2>/dev/null)"'
IOSchedulingClass=idle
CPUSchedulingPolicy=idle
StandardInput=null
StandardOutput=null
StandardError=null
~/.config/systemd/user/myip.timer
:
# activate by: systemctl --user enable myip.timer
[Unit]
Description=Check external IP address
Documentation=man:myip(1)
[Timer]
# 90 sec min is enough for connecting to new Wifi service
OnStartupSec=90
[Install]
WantedBy=timers.target
Activating timer service
$ systemctl --user enable myip.timer
This creates a symlink ~/.config/systemd/user/timers.target.wants/myip.timer
pointing to ~/.config/systemd/user/myip.timer
Checking logged IPs
IP address as I powered-on this time.
$ journalctl -a -b -t myip
IP address as I powered-on recently.
$ journalctl -a -t myip
Previous Post | Top | Next Post |