Get the only ip (nothing else) of my linux machine?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the only ip (nothing else) of my linux machine?
# 1  
Old 06-30-2010
Get the only ip (nothing else) of my linux machine?

How i can get the only ip (nothing else) of my linux machine using shell script.
# 2  
Old 06-30-2010
Code:
hostname -i

# 3  
Old 06-30-2010
I need the network IP not local. The ip that i can get from ifconfig.
# 4  
Old 06-30-2010
If you have DNS and dig:
Code:
dig +short $(hostname -f)

Or, a bit longer:
Code:
ip addr show <interface> | sed -ne '/inet/s/.* \([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/p'

# 5  
Old 06-30-2010
Tnx buddies, i have got it Smilie

Code:
OS=`uname`
IO="" # store IP
case $OS in
   Linux) IP=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;
   FreeBSD|OpenBSD) IP=`ifconfig  | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;
   SunOS) IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;
   *) IP="Unknown";;
esac

echo "$IP"


Last edited by radoulov; 06-30-2010 at 04:26 AM.. Reason: Please use code tags!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How do we check the Linux machine OS?

I have IBM Z-Linux machine as well as RedHat Linux. Where do I see that the particular machine is z-Linux? below output from zlinux. $ uname -a Linux xxxxxxxHostname 2.6.18-406.el5 #1 SMP Fri May 1 10:42:26 EDT 2015 s390x s390x s390x GNU/Linux below output from redhat. $ uname -a... (3 Replies)
Discussion started by: govindts
3 Replies

2. Linux

Dhcp in use or not for Linux machine

Hi All. Can anyone let me know the smartest and fullprrof method of checkking whther any given linux machine is using DHCP or not? # ps -ef | grep dhcp gives output like below : root 3251 3128 0 11:02 pts/0 00:00:00 grep dhcp so i dont think its full proof method , please... (3 Replies)
Discussion started by: omkar.jadhav
3 Replies

3. Red Hat

how to install Openssh in linux machine

Hi genious i'm New to Linux .. help me Very Urgent how to install Openssh in linux machine step by step .... plz (3 Replies)
Discussion started by: coolboys
3 Replies

4. Red Hat

How to LINUX machine as a router.

Hi guys, could you help me to configure my Linux machine to behave as router? Scenario: Machine OS: CentOS 6.2 NIC: eth0: configured with a static IP by the ISP. eth1: not configured yet Virtual Machine: CentOS 5.7 NIC : eth0 : not configured yet eth1 : not configured yet... (8 Replies)
Discussion started by: saqlain.bashir
8 Replies

5. Shell Programming and Scripting

shell script to copy files frm a linux machine to a windows machine using SCP

I need a shell script to copy files frm a linux machine to a windows machine using SCP. The files keeps changing day-to-day. I have to copy the latest file to the windows machine frm the linux machine. for example :In Linux, On July 20, the file name will be 20.txt and it should be copied to... (3 Replies)
Discussion started by: nithin6034
3 Replies

6. UNIX for Dummies Questions & Answers

Linux machine performance issue.

One of our database server is suddenly became very slow and i have no clue what to do .Please help. I m sharing the performance inforamtion regarding cpu,harddisk,ram . ########CPU Information######## Machine Uptime Information: uptime 10:25:06 up 16:50, 1 user, load average: 5.84, 5.65,... (10 Replies)
Discussion started by: pinga123
10 Replies

7. Shell Programming and Scripting

SSH into a linux machine from a windows machine

I basically want to login into different linux machines( on the same network) from a windows machine. I know i can use ssh <machine name>. But i want to automate this process. I dont want to enter the username and password. Is there any way to do it. Can i make some sort of a batch script for it. (4 Replies)
Discussion started by: lassimanji
4 Replies

8. UNIX Desktop Questions & Answers

more than one linux on same machine?????

can i install more than one linux on a same machine......... i.e fedora and Kubuntu on asame machine..... will it affect a performance?????? (2 Replies)
Discussion started by: arunchaudhary19
2 Replies

9. Shell Programming and Scripting

how to execute C code in linux machine

Hi. I have a C code i want to run that code in linux machine. i tried with CC command. but CC command not in my bin dir. how to run that script. regards rajan (3 Replies)
Discussion started by: rajan_ka1
3 Replies

10. Shell Programming and Scripting

How to synchronize all the linux machine?

Hi, I have three Linux machine have three different times. Can I synchronize them using one process? I have root access. Thanks! (1 Reply)
Discussion started by: whatisthis
1 Replies
Login or Register to Ask a Question