how to check my ip ubuntu code example

Example 1: ubuntu check public ip command line

#4 Ways to Find Server Public IP Address in Linux Terminal
#1. Using dig Utility
dig +short myip.opendns.com @resolver1.opendns.com
#2. Using host Utility
host myip.opendns.com resolver1.opendns.com | grep "myip.opendns.com has" | awk '{print $4}'
#3. Using wget Command Line Downloader
wget -qO- http://ipecho.net/plain | xargs echo
wget -qO - icanhazip.com
#4. Using cURL Command Line Downloader
 curl ifconfig.co
 curl ifconfig.me
 curl icanhazip.com

Example 2: change ubuntu ip address command line

#/etc/netplan/99_config.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses: [10.10.10.2/24]
      gateway4: 10.10.10.1
      nameservers:
          search: [mydomain, otherdomain]
          addresses: [9.9.9.9, 1.1.1.1]

Example 3: ip address ubuntu

ip address show