Finding the Private IP Address
1. Using ip
command:
bash
Copy code
ip addr
Or to get a more concise output for a specific interface (e.g., eth0):
bash
Copy code
ip a show eth0
For IPv4 only:
bash
Copy code
ip -4 addr show eth0
For IPv6 only:
bash
Copy code
ip -6 addr show eth0
2. Using ifconfig (Deprecated, but still useful in some systems):
bash
Copy code
ifconfig
To get details of a specific interface:
bash
Copy code
ifconfig eth0
3. Using hostname command:
bash
Copy code
hostname -I
4. Using nmcli command (for systems using NetworkManager):
bash
Copy code
nmcli -p device show
Finding the Public IP Address
1. Using curl command:
bash
Copy code
curl ifconfig.me
Other services you can use with curl:
bash
Copy code
curl ipinfo.io/ip
curl api.ipify.org
curl icanhazip.com
2. Using dig command:
bash
Copy code
dig +short myip.opendns.com @resolver1.opendns.com
These methods cover different ways to check both the private and public IP addresses on a Linux server. You can choose the command based on your preferences and the tools available on your system.