Show local ip inside .sh script [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-3
down vote

favorite












We want to show local server ip inside .sh script, any ideas how this could be done ?










share|improve this question















closed as too broad by roaima, steve, Jeff Schaller, G-Man, maxschlepzig Nov 24 at 12:48


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 2




    That's not an example. If you want an answer without even bothering to try then why not buy some consultancy.
    – roaima
    Nov 23 at 21:42














up vote
-3
down vote

favorite












We want to show local server ip inside .sh script, any ideas how this could be done ?










share|improve this question















closed as too broad by roaima, steve, Jeff Schaller, G-Man, maxschlepzig Nov 24 at 12:48


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 2




    That's not an example. If you want an answer without even bothering to try then why not buy some consultancy.
    – roaima
    Nov 23 at 21:42












up vote
-3
down vote

favorite









up vote
-3
down vote

favorite











We want to show local server ip inside .sh script, any ideas how this could be done ?










share|improve this question















We want to show local server ip inside .sh script, any ideas how this could be done ?







linux bash shell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 at 21:42









roaima

42.2k550115




42.2k550115










asked Nov 23 at 20:49









Ali EL KANDOUSSI

54




54




closed as too broad by roaima, steve, Jeff Schaller, G-Man, maxschlepzig Nov 24 at 12:48


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as too broad by roaima, steve, Jeff Schaller, G-Man, maxschlepzig Nov 24 at 12:48


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2




    That's not an example. If you want an answer without even bothering to try then why not buy some consultancy.
    – roaima
    Nov 23 at 21:42












  • 2




    That's not an example. If you want an answer without even bothering to try then why not buy some consultancy.
    – roaima
    Nov 23 at 21:42







2




2




That's not an example. If you want an answer without even bothering to try then why not buy some consultancy.
– roaima
Nov 23 at 21:42




That's not an example. If you want an answer without even bothering to try then why not buy some consultancy.
– roaima
Nov 23 at 21:42










1 Answer
1






active

oldest

votes

















up vote
1
down vote













You can use something like this:



localiphere=$(hostname -i)


But the exact command to be used inside the parenthesis depends on how many IPs you have on a server and which distribution you are using.



Basically, you need to put the command which will return the server IP, but that command will vary from system to system. On Debian hostname -i will return the main server IP.



If you are looking for server public IP and not private IPs, even if you have multiple public IPs on your server, you can use online services like ifconfig.co and similar to get main public IP of the server regardless of the system you are running.



localiphere=$(curl ifconfig.co)





share|improve this answer






















  • With RHEL7: hostname -I
    – Cyrus
    Nov 23 at 21:57










  • In my Debian hostname -i returns 127.0.0.1 while hostname -I returns 192.168.1.120
    – George Vasiliou
    Nov 25 at 21:47










  • -I should return all IP addresses, from manpage, [-I|--all-ip-addresses], it returns all IPs on all Debians I tried it.
    – rAlen
    Nov 26 at 5:42

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













You can use something like this:



localiphere=$(hostname -i)


But the exact command to be used inside the parenthesis depends on how many IPs you have on a server and which distribution you are using.



Basically, you need to put the command which will return the server IP, but that command will vary from system to system. On Debian hostname -i will return the main server IP.



If you are looking for server public IP and not private IPs, even if you have multiple public IPs on your server, you can use online services like ifconfig.co and similar to get main public IP of the server regardless of the system you are running.



localiphere=$(curl ifconfig.co)





share|improve this answer






















  • With RHEL7: hostname -I
    – Cyrus
    Nov 23 at 21:57










  • In my Debian hostname -i returns 127.0.0.1 while hostname -I returns 192.168.1.120
    – George Vasiliou
    Nov 25 at 21:47










  • -I should return all IP addresses, from manpage, [-I|--all-ip-addresses], it returns all IPs on all Debians I tried it.
    – rAlen
    Nov 26 at 5:42














up vote
1
down vote













You can use something like this:



localiphere=$(hostname -i)


But the exact command to be used inside the parenthesis depends on how many IPs you have on a server and which distribution you are using.



Basically, you need to put the command which will return the server IP, but that command will vary from system to system. On Debian hostname -i will return the main server IP.



If you are looking for server public IP and not private IPs, even if you have multiple public IPs on your server, you can use online services like ifconfig.co and similar to get main public IP of the server regardless of the system you are running.



localiphere=$(curl ifconfig.co)





share|improve this answer






















  • With RHEL7: hostname -I
    – Cyrus
    Nov 23 at 21:57










  • In my Debian hostname -i returns 127.0.0.1 while hostname -I returns 192.168.1.120
    – George Vasiliou
    Nov 25 at 21:47










  • -I should return all IP addresses, from manpage, [-I|--all-ip-addresses], it returns all IPs on all Debians I tried it.
    – rAlen
    Nov 26 at 5:42












up vote
1
down vote










up vote
1
down vote









You can use something like this:



localiphere=$(hostname -i)


But the exact command to be used inside the parenthesis depends on how many IPs you have on a server and which distribution you are using.



Basically, you need to put the command which will return the server IP, but that command will vary from system to system. On Debian hostname -i will return the main server IP.



If you are looking for server public IP and not private IPs, even if you have multiple public IPs on your server, you can use online services like ifconfig.co and similar to get main public IP of the server regardless of the system you are running.



localiphere=$(curl ifconfig.co)





share|improve this answer














You can use something like this:



localiphere=$(hostname -i)


But the exact command to be used inside the parenthesis depends on how many IPs you have on a server and which distribution you are using.



Basically, you need to put the command which will return the server IP, but that command will vary from system to system. On Debian hostname -i will return the main server IP.



If you are looking for server public IP and not private IPs, even if you have multiple public IPs on your server, you can use online services like ifconfig.co and similar to get main public IP of the server regardless of the system you are running.



localiphere=$(curl ifconfig.co)






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 26 at 5:47

























answered Nov 23 at 21:23









rAlen

675410




675410











  • With RHEL7: hostname -I
    – Cyrus
    Nov 23 at 21:57










  • In my Debian hostname -i returns 127.0.0.1 while hostname -I returns 192.168.1.120
    – George Vasiliou
    Nov 25 at 21:47










  • -I should return all IP addresses, from manpage, [-I|--all-ip-addresses], it returns all IPs on all Debians I tried it.
    – rAlen
    Nov 26 at 5:42
















  • With RHEL7: hostname -I
    – Cyrus
    Nov 23 at 21:57










  • In my Debian hostname -i returns 127.0.0.1 while hostname -I returns 192.168.1.120
    – George Vasiliou
    Nov 25 at 21:47










  • -I should return all IP addresses, from manpage, [-I|--all-ip-addresses], it returns all IPs on all Debians I tried it.
    – rAlen
    Nov 26 at 5:42















With RHEL7: hostname -I
– Cyrus
Nov 23 at 21:57




With RHEL7: hostname -I
– Cyrus
Nov 23 at 21:57












In my Debian hostname -i returns 127.0.0.1 while hostname -I returns 192.168.1.120
– George Vasiliou
Nov 25 at 21:47




In my Debian hostname -i returns 127.0.0.1 while hostname -I returns 192.168.1.120
– George Vasiliou
Nov 25 at 21:47












-I should return all IP addresses, from manpage, [-I|--all-ip-addresses], it returns all IPs on all Debians I tried it.
– rAlen
Nov 26 at 5:42




-I should return all IP addresses, from manpage, [-I|--all-ip-addresses], it returns all IPs on all Debians I tried it.
– rAlen
Nov 26 at 5:42


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay