works on Linux and Solaris. I think it will work on nearly all *nix-es Show Sample Output
Fetches the IPs and ONLY the IPs from ifconfig. Simplest, shortest, cleanest. Perl is too good to be true... (P.S.: credit should go to Peteris Krumins at catonmat.net) Show Sample Output
This is useful if you have need to do port forwarding and your router doesn't assign static IPs, you can add it to a script in a cron job that checks if you IP as recently changed or with a trigger script. This was tested on Mac OSX.
Next time you are leaching off of someone else's wifi use this command before you start your bittorrent ...for legitimate files only of course. It creates a hexidecimal string using md5sum from the first few lines of /dev/urandom and splices it into the proper MAC address format. Then it changes your MAC and resets your wireless (wlan0:0). Show Sample Output
eth0 = the name of the interface 00:01:02:03:04:05 = the new mac adresse the same thing for wireless card $ sudo iwconfig eth1 hw ether 00:01:02:03:04:05
Interfaces like lo can be omitted from the beginning, there are probably better ways of doing this, i'm a noob at awk. Show Sample Output
I've been using it in a script to build from scratch proxy servers. Show Sample Output
Will return your internal IP address. Show Sample Output
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.
Get mac address listed for all interfaces. Show Sample Output
For machines that have many ip blocks spanning different Class C's, this will show which ones. Show Sample Output
On the Mac, the format ifconfig puts out is little different from Linux: the IP address is space separated, instead of colon. That makes parsing the IP address easier. See releated command for Linux/Unix: http://www.commandlinefu.com/commands/view/651/getting-the-ip-address-of-eth0 Show Sample Output
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. Show Sample Output
Simple and easy. No regex, no search and replace. Just clean, built-in tools.
Needed to get the Mac of various devices on a solaris box, but didn't have root. This command used awk to display the Network device, the IP, and the MAC a line at a time.
and, a lot uglier, with sed:
ifconfig | sed -n '/inet addr:/s/[^:]\+:\(\S\+\).*/\1/p'
Edit:
Wanted to be shorter than the perl version. Still think that the perl version is the best..
The initial version of this command also outputted extra empty lines, so it went like this: 192.168.166.48 127.0.0.1 This happened on Ubuntu, i haven't tested on anything else. Show Sample Output
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:
modprobe iptable_nat
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
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: