commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
This assumes your local ip starts with 192.something (e.g. 192.168), it greps ifconfig output for an ip that starts with 192, then strips the extra garbage (besides the ip)
Maybe `ifconfig | grep addr | grep Bcast` would also do it
Easy way to grab the IP address of a machine for easy script use. If needed a "| grep -v 127.0.0.1" at the end will suppress localhost.
Get mac address listed for all interfaces.
HP UX doesn't have a -a switch in the ifconfig command.
This line emulates the same result shown in Solaris, AIX or Linux
the below command create a alias for share your internet connection with another.
ifconfig eth0:1 192.168.0.1/24
Its obviously necessary too activate the iptables post-routing and ip forwarding, as root:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward
Be sure that the alias 192.168.0.0/24 is not your active real ip range
Get the line containing "inet addr:" and the line before that, get down to only the first line, and then get the first word on that line, which should be the interface.
same thing as the other
grabs your local IP Address.
Simple MAC adrress, thanks to ifconfig.
Sometimes, you don't really care about all the other information that ifconfig spits at you (however useful it may otherwise be). You just want an IP. This strips out all the crap and gives you exactly what you want.
Gets the internal and external IP addresses of all your interfaces, or the ones given as arguments
Will return your internal IP address.
The example command deletes all aliases for network interface 'em0' assuming that the aliases have netmask of 255.255.255.255 and the master IP has some other netmask (such as 255.255.255.0). See here -> http://my.galagzee.com/2009/07/22/deleting-all-network-interface-aliases/ for more on the rationale of this command.
works on Linux and Solaris. I think it will work on nearly all *nix-es
The initial version of this command also outputted extra empty lines, so it went like this:
This happened on Ubuntu, i haven't tested on anything else.
and, a lot uglier, with sed:
ifconfig | sed -n '/inet addr:/s/[^:]\+:\(\S\+\).*/\1/p'
Wanted to be shorter than the perl version. Still think that the perl version is the best..
Get the IP address of all your network cards.