Just store the address in a variable and then you can ping that:
$ foo=unix.stackexchange.com
$ ping "$foo"
PING unix.stackexchange.com (104.18.43.226) 56(84) bytes of data.
64 bytes from 104.18.43.226 (104.18.43.226): icmp_seq=1 ttl=58 time=5.12 ms
64 bytes from 104.18.43.226 (104.18.43.226): icmp_seq=2 ttl=58 time=10.5 ms
64 bytes from 104.18.43.226 (104.18.43.226): icmp_seq=3 ttl=58 time=8.05 ms
^C
--- unix.stackexchange.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 5.120/7.901/10.532/2.212 ms
To make it permanent, edit your ~/.profile file (or ~/.bash_profile if that file exists and you are using bash) and add this line (of course, change foo to whatever you want your variable to be called and change the URL to the name of your server):
export foo=unix.stackexchange.com
Now, from the next time you log in, you will be able to run ping "$foo" to ping, or echo "$foo" to print it out etc.
ping "$name"? – terdon Nov 05 '23 at 13:37And as an answer to your question, I don't know anything about variables, it may work but I'm not sure... Can you show me how, please?
As I said, I use /etc/hosts for static IPs, but it doesn't work for DNS domain name.
– Abd Alhaleem Bakkor Nov 05 '23 at 15:09I'm looking into linux variables now as terdon mentioned them, I will update if I have any success with that.
– Abd Alhaleem Bakkor Nov 05 '23 at 15:18I don't think they are useful for DNS stuff.
Maybe ip addr , dnsmasq or some other networking service?! All I need is to call that long name as short one... Thanks
– Abd Alhaleem Bakkor Nov 05 '23 at 15:29homeinstead. This is exactly what you want if I understand your question correctly. So, the answers are the same here and there. – xhienne Nov 05 '23 at 15:52