Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need a command or script to return my ip address by interface. I know u can see what it is by ifconfig, but I need just the ip address returned to dump in say...an environment variable, that i can later reference in a script. I tried "hostname -i" but it just returns the loopback address. I need to be able to get ip address for say eth0 or eth1. This would be on a redhat 9.0 box.
I never actually thought before but if it was your external IP and you are behind a firewall then you can also use:
lynx -dump http://www.whatismyip.com | awk '/^Your IP is/ { print $4; }'
Why is this so hard? I have 2 wireless nets and 2 NICs hooking the little oracle/freeciv Ubuntu server up. How does the person tell which ip they've hooked to? I put up a telnet server so the Windoze here at home can get to it without installing putty or cygwin. They can start networked freeciv games from a simple menu. Showing which IP they connected to, so they know which one to put in the Windoze freeciv client, should be trivial, but it isn't. I put a variable into the .profile for the captive id/menu I use to give control of freeciv. It contains the Shell PID. Here's the resulting kludge. Where is the 'who -whatipaddresdidIhit' option?
#!/usr/bin/ksh
# ---------------------------------------------------
# This kludge walks up the pid tree looking for the telnetd pid.
# It uses that pid to get the ip with lsof...I had to put setuid
# on lsof for this to work. Blechh!!
# ---------------------------------------------------
# NOTE: for the sed stuff, there is a <space><tab> inside the [ ]
# ---------------------------------------------------
PID_OF_INTEREST=$MyPID
while true
do
if ps -ef | grep "^[^ ][^ ]*[ ][ ]*${PID_OF_INTEREST}[ ][ ]*" | grep 'telnetd.*in.telnetd:' > /dev/null 2>&1
then
break
fi
PID_OF_INTEREST=$(ps -ef | grep "^[^ ][^ ]*[ ][ ]*${PID_OF_INTEREST}[ ][ ]*" | awk '{print $3}')
done
lsof -i4 -n | grep "$PID_OF_INTEREST" |
head -1 |
sed 's/.*[ ]\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\):telnet.*/\1/'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.