Frequently, you might need to retrieve and use your public IP addresses in various scenarios. These aliases, ip6
and ip4
, simplify the process of obtaining your public IPv6 and IPv4 addresses and copying them to your clipboard.
You can add the ip6
and ip4
aliases to your shell configuration files (.bashrc
, .bash_profile
, or .zshrc
) for convenient access in every terminal session. Follow these steps to add and use the aliases in your shell configuration:
-
Open Visual Studio Code or your preferred code editor.
-
For Bash (
.bashrc
or.bash_profile
) and Zsh (.zshrc)
:a. Bash Configuration: If you're using Bash, open your Bash configuration file. Depending on your system, it might be either
~/.bashrc
or~/.bash_profile
.b. Zsh Configuration: If you're using Zsh, open your Zsh configuration file, typically
~/.zshrc
. -
Copy and Paste: Copy and paste the following aliases at the end of your configuration file:
# Get your public IPv6 address and copy it to the clipboard alias ip6="curl ipv6.icanhazip.com/ --silent | xargs -I %s sh -c 'echo %s | pbcopy; echo %s;'" # Get your public IPv4 address and copy it to the clipboard alias ip4="curl ipv4.icanhazip.com/ --silent | xargs -I %s sh -c 'echo %s | pbcopy; echo %s;'"
-
Save the Changes: Save the changes to your configuration file.
-
Reload the Configuration:
-
For Bash: In your terminal, either restart your terminal or run:
source ~/.bashrc
-
For Zsh: In your terminal, either restart your terminal or run:
source ~/.zshrc
-
-
Usage: You can now use the
ip6
andip4
aliases in your Bash or Zsh shell to quickly retrieve and copy your public IPv6 and IPv4 addresses to the clipboard.-
To get your IPv6 address and copy it to the clipboard:
ip6
-
To get your IPv4 address and copy it to the clipboard:
ip4
-
Adding these aliases to your shell configuration enhances your command-line experience by simplifying the process of obtaining and using your public IPv6 and IPv4 addresses. These custom aliases are valuable for various networking and development tasks.